• Gridview中绑定DropDownList


    1、页面代码

    复制代码
                            <asp:TemplateField HeaderText="等级">
                                
    <ItemTemplate>
                                    
    <asp:Label ID="Label6" runat="server" Text='<%# FormatUserlevel(Eval("User_UserLevel"))%>'></asp:Label>
                                
    </ItemTemplate>
                                
    <EditItemTemplate>
      //这个label的作用是为了在后台控制 
    当你点击编辑按钮的时 DropDownList 的选中值,                         <asp:Label ID="Label7" runat="server" Text='<%# Eval("User_UserLevel")%>' Visible="false"></asp:Label>
                                    
    <asp:DropDownList ID="ddl_userLevel" runat="server" >
                                    
    </asp:DropDownList>
                                
    </EditItemTemplate>
                            
    </asp:TemplateField>
    复制代码

    将此列设为模版,在现实数据的时候是以label形式,当点击控件自带的编辑按钮的时候就是以DropDownList形势显示

    2、后台代码

    复制代码

    1、页面代码

    复制代码
                            <asp:TemplateField HeaderText="等级">
                                
    <ItemTemplate>
                                    
    <asp:Label ID="Label6" runat="server" Text='<%# FormatUserlevel(Eval("User_UserLevel"))%>'></asp:Label>
                                
    </ItemTemplate>
                                
    <EditItemTemplate>
      //这个label的作用是为了在后台控制 
    当你点击编辑按钮的时 DropDownList 的选中值,                         <asp:Label ID="Label7" runat="server" Text='<%# Eval("User_UserLevel")%>' Visible="false"></asp:Label>
                                    
    <asp:DropDownList ID="ddl_userLevel" runat="server" >
                                    
    </asp:DropDownList>
                                
    </EditItemTemplate>
                            
    </asp:TemplateField>
    复制代码

    将此列设为模版,在现实数据的时候是以label形式,当点击控件自带的编辑按钮的时候就是以DropDownList形势显示

    2、后台代码

    复制代码
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        
    {
            SystemMemberLevel bll 
    = new SystemMemberLevel();
            IList
    <SystemMemberLevelModel> list = bll.GetAllList();
            
    if (e.Row.RowType == DataControlRowType.DataRow)
            
    {
                DropDownList ddl 
    = ((DropDownList)e.Row.FindControl("ddl_userLevel"));
                Label lb 
    = ((Label)e.Row.FindControl("Label7"));

                
    if (ddl != null)
                
    {
                    ddl.DataSource 
    = list;
                    ddl.DataTextField 
    = "name";
                    ddl.DataValueField 
    = "id";
                    ddl.SelectedValue 
    = lb.Text;
                    ddl.DataBind();
                }
      
            }

        }
    复制代码
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        
    {
            SystemMemberLevel bll 
    = new SystemMemberLevel();
            IList
    <SystemMemberLevelModel> list = bll.GetAllList();
            
    if (e.Row.RowType == DataControlRowType.DataRow)
            
    {
                DropDownList ddl 
    = ((DropDownList)e.Row.FindControl("ddl_userLevel"));
                Label lb 
    = ((Label)e.Row.FindControl("Label7"));

                
    if (ddl != null)
                
    {
                    ddl.DataSource 
    = list;
                    ddl.DataTextField 
    = "name";
                    ddl.DataValueField 
    = "id";
                    ddl.SelectedValue 
    = lb.Text;
                    ddl.DataBind();
                }
      
            }

        }
    复制代码
  • 相关阅读:
    动易CMS 实现ctrl+v粘贴图片并上传、word粘贴带图片
    帝国CMS 实现ctrl+v粘贴图片并上传、word粘贴带图片
    php大文件上传(切片)工具
    php大文件上传(分块)
    php大文件上传(分片)
    Nginx大文件上传(切片)
    百度WebUploader大文件上传(切片)
    WebUploader大文件上传(切片)
    html5大文件上传(切片)
    jquery大文件上传(切片)
  • 原文地址:https://www.cnblogs.com/lyl6796910/p/3746622.html
Copyright © 2020-2023  润新知