• 获取CheckBox在GridView模板列中的值


    aspx:
        <asp:GridView ID="gvdeptusers" runat="server" DataKeyNames="id" AutoGenerateColumns="False" Width="100%" ShowHeader="False" OnRowDataBound="gvdeptusers_RowDataBound">
        
    <Columns>
            
    <asp:BoundField DataField="names" >
                
    <ItemStyle Width="8%" HorizontalAlign="Center" />                
                
    </asp:BoundField>
            
    <asp:BoundField DataField="deptname" >
                
    <ItemStyle Width="10%" HorizontalAlign="Center" />                
                
    </asp:BoundField>
            
    <asp:TemplateField>
                
    <ItemTemplate>
                    
    <asp:HiddenField ID="hdtype" runat="server" Value='<%# Eval("user_classid") %>' />
                    
    <asp:CheckBox ID="cbusers" Text='<%# Eval("username") %>' runat="server" />
                 
    </ItemTemplate>
            
    </asp:TemplateField>
        
    </Columns>
    </asp:GridView>

    cs:
                string idStr = "";
                
    foreach (GridViewRow row in this.gvdeptusers.Rows)
                

                    
    if (((CheckBox)row.FindControl("cbusers")).Checked == true)
                    
    {
                        idStr 
    += this.gvdeptusers.DataKeys[row.RowIndex].Value + "<br>";
                    }

                }

                Response.Write(idStr);
                Response.End();

    绑定选定值:
            protected void gvdeptusers_RowDataBound(object sender, GridViewRowEventArgs e)
            
    {
                
    int strid = e.Row.RowIndex;
                CheckBox cbusers 
    = (CheckBox)e.Row.FindControl("cbusers");
                
    if (cbusers != null)
                
    {
                    
    string strhdtype = ((HiddenField)e.Row.FindControl("hdtype")).Value;
                    
    if (strhdtype != "1" && strhdtype != "8") cbusers.Checked = true;
                }

            }

    很简单的代码,怕忘记所以记录于此。
  • 相关阅读:
    面试题19:包含min函数的栈
    编程之美 计算字符串的相似度
    android 数据持久化——I/O操作
    SSD磁盘,CPU居高不下,高并发的情况下,是不是mysql解析器耗费的cpu资源高?
    Eclipse、MyEclipse优化,提高运行速度
    Sonar入门学习
    Oracle 生成指定范围内随机日期
    ios中的GCD
    如何使用Win8系统自带杀毒软件
    安装Ubuntu版本linux过程中没有提示设置root用户密码问题的解决办法
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/725425.html
Copyright © 2020-2023  润新知