关闭

GridView中Checkbox使用一列

426人阅读 评论(0) 收藏 举报
  <asp:GridView ID="GridViewAllUser" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" PageSize="1" RowHeaderColumn="UserID" DataSourceID="ObjectDataSource1" DataKeyNames="UserID">
                
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                
<EditRowStyle BackColor="#999999" />
                
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                
<Columns>
                    
<asp:BoundField DataField="UserID" HeaderText="UserID" />
                    
<asp:BoundField DataField="UserName" HeaderText="UserName" />
                    
<asp:BoundField DataField="LastActivityDate" />
                    
<asp:TemplateField HeaderText="IsApproved" SortExpression="IsApproved">
                
<EditItemTemplate>
                    
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("IsApproved") %>' />
                
</EditItemTemplate>
                
<ItemTemplate>
                    
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Checked='<%# Bind("IsApproved") %>' OnCheckedChanged="CheckBox1_CheckedChanged"
                         
/>
                
</ItemTemplate>
            
</asp:TemplateField>
                
</Columns>
            
</asp:GridView>
           
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllRoles"
        TypeName
="AgTrade.WebSite.admin.UserManage"></asp:ObjectDataSource>

 

 


        
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        
{
            CheckBox cb 
= sender as CheckBox;
            GridViewRow gvr 
= cb.Parent.Parent as GridViewRow;
            
string userName = GridViewAllUser.DataKeys[gvr.RowIndex].Value.ToString();
           
        }

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:217124次
    • 积分:3165
    • 等级:
    • 排名:第10815名
    • 原创:90篇
    • 转载:32篇
    • 译文:0篇
    • 评论:28条
    文章分类