zoukankan      html  css  js  c++  java
  • 获取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;
                }

            }

    很简单的代码,怕忘记所以记录于此。
  • 相关阅读:
    [转]win7 系统装SQLServer2000 成功。
    Windows CE 电源管理(转贴)
    [转]Win7系统下VS2005_2008不识别WinCE5 SDK
    [转]windows 7 下ASP.net 本地配置 ( IIS 7)
    [转]SelectObject() 装载字体 VC EVC
    Mobile Development: Disable Windows Mobile 6.5 Start and Close Button
    [转]WebForm 与 winform 路径获取
    1. chromedriver的下载和配置
    Slf4j打印异常的堆栈信息
    写个日志请求切面,前后端甩锅更方便
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/725425.html
Copyright © 2011-2022 走看看