<asp:TemplateField HeaderText="姓名">
                                            <ItemStyle Width="80px" />
                                                <ItemTemplate>
                                                    <%# Eval("RealName")%>
                                                </ItemTemplate>                                                <EditItemTemplate>
                                            <asp:DropDownList ID="editName" runat="server"  Width="50px">
                                           <asp:ListItem>
                                                   ???????
                                           </asp:ListItem>
                                            </asp:DropDownList>
                                                </EditItemTemplate>
                                       </asp:TemplateField>现在我想在DropDownList绑定数据库里对应的值,请问怎么做呀曾经用输入框 这样写可以,<asp:TextBox ID="editName" runat="server" Text='<%# Eval("RealName") %>' Width="50px"></asp:TextBox>但是同理的 我就想换成DropDownList

解决方案 »

  1.   


    <asp:TemplateField HeaderText="姓名">
      <ItemStyle Width="80px" />
      <ItemTemplate>
      <%# Eval("RealName")%>
      </ItemTemplate>  <EditItemTemplate>
      <asp:DropDownList ID="editName" runat="server" Width="50px">
      <asp:ListItem>
      ???????
      </asp:ListItem>
      </asp:DropDownList>
      </EditItemTemplate>
      </asp:TemplateField>现在我想在DropDownList绑定数据库里对应的值,请问怎么做呀曾经用输入框 这样写可以,<asp:TextBox ID="editName" runat="server" Text='<%# Eval("RealName") %>' Width="50px"></asp:TextBox>但是同理的 我就想换成DropDownList
      

  2.   

    在ItemBouding事件给控件绑定内容
      

  3.   

    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowIndex != -1) {
    if (e.Row.RowState == DataControlRowState.Edit || Convert.ToInt32(e.Row.RowState & DataControlRowState.Edit) != 0) {
    DropDownList ddl = e.Row.FindControl("ddl") as DropDownList;
    ddl.SelectedValue = ((HiddenField)e.Row.FindControl("Hf")).Value; }
    }}
    protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
    {
    gv.EditIndex = e.NewEditIndex;
    BindData();
    }
    protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    gv.EditIndex = e.RowIndex;
    int id = int.Parse(gv.DataKeys(e.RowIndex).Value.ToString());
    string str = ((DropDownList)gv.Rows(e.RowIndex).FindControl("ddl")).SelectedValue.Trim();
    }
      

  4.   

    自己看
    http://hi.baidu.com/veyshy/blog/item/bf0fbe89c0eaab00b31bbaa5.html
      

  5.   

    可以看教程:http://www.aspx2.com/AspNET/ASPNETShuJuCaoZuoJiaoChe.html