如题,GridView控件绑定某表数据,表数据某列在编辑时,用DropDownList表示,现在GridView进入编辑状态,我需要DropDownList所选中的值是所对应记录的那个值。
Please help me!

解决方案 »

  1.   

    可以用javascript来做,dropdownlist.value="选中列的值"即可
      

  2.   

    我就是不知道GridView中在编辑状态下,当前列的值如何取得并给DropDownList
      

  3.   

    你在DropDownList1那列的编辑模板列中加入一个HiddenField .给它绑定当前该条记录
    应该在DropDownList1上显示数据的Value值.用它来保存DropDownList1应该显示的值.
    在GridView1_RowDataBound事件中再它当前记录应该显示的值赋给DropDownList1.<EditItemTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server">
    <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("字段") %>' />
    </EditItemTemplate>
     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (((DropDownList)e.Row.FindControl("DropDownList1")) != null)
            {
                DropDownList1.SelectedValue = ((HiddenField)e.Row.FindControl("HiddenField1")).Value;
            }
       }
      

  4.   

    DropDownList1显示的数据要不你在DropDownList1中写死了(包括它的text值与value值)
    要不你在后台给它绑定数据.        DropDownList1.DataSource="数据源";
            DropDownList1.DataTextField="字段";
            DropDownList1.DataValueField="它段";
            DropDownList1.DataBind();
      

  5.   

    出去了一天多,回来又发现网络问题,今天试了加visible=false项,不行,不过没试过你上面的那种加在<EditItemTemplate /> 之间的,我会试一下,先谢了
      

  6.   

    Wow! It's work, thank you!