• 在GridView中添加下拉框来更新数据?


    在GridView中添加下拉框来更新数据?

    • 前台代码

       <asp:TemplateField HeaderText="物品名称">
                                      <ItemTemplate>
                                          <asp:Label ID="Label1" runat="server" Text='<%#Eval("GoodName") %>'></asp:Label>
                                      </ItemTemplate>
                                      <EditItemTemplate>
                                          <asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
                                      </EditItemTemplate>
                                  </asp:TemplateField>
      
    • 后台代码

      • 在GridView1_RowEditing事件中进行数据绑定

        DropDownList  drop2 = GridView1.Rows[e.NewEditIndex].FindControl("DropDownList2") as DropDownList;
        //找到该控件,然后进行数据绑定
                        drop2.DataSource = BLL.Manages.Seldrop();
                        drop2.DataTextField = "GoodName";
                        drop2.DataValueField = "GoodID";
                        drop2.DataBind();
        
      • 在GridView1_RowUpdating事件中就可以获取下拉选

        DropDownList  drop=
          GridView1.Rows[e.RowIndex].Cells[3].FindControl("DropDownList2")   as  DropDownList;
        //找到这个控件
        
        string GoodID = drop.SelectedValue;
        
    每个人都是在努力的路上,别因为别人的误解而放弃,,术业有专攻,如是而已。
  • 相关阅读:
    新人讲解
    为人处世
    项目管理
    读书
    游戏
    总结反思
    地图相关
    产品经理
    摄影
    Java 邮件发送
  • 原文地址:https://www.cnblogs.com/16699qq/p/13361186.html
Copyright © 2020-2023  润新知