gridview中的复选框 [英] checkbox in the gridview

查看:80
本文介绍了gridview中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含userid,productid,permission的表.从页面插入Userid和productid,由于默认值为false,权限自动变为false.现在,我想在网格视图中显示userid,productid和权限,如果admin希望它可以检查并实现权限.

我在页面上勾选了一个复选框,当checkbox.checked选中了rowdatabound时! = null,然后我插入true并在session中获取该值.然后更新表中的按钮,单击但检查复选框不起作用.

I have a table which contains userid,productid,permission . Userid and productid are inserted from a page and permission is getting false automatically since default value is false . Now i want to show the userid ,productid and permission in a grid view and if admin wants it will check and make true the permission .

I take a checkbox on the page for that and on rowdatabound when checkbox.checked ! = null then i inserted true and take that value in session . And then update in the table on the button click but checking the check box not working .

推荐答案



在这里,我编写了一些代码来检查数据控件中的复选框

Hi,

Here I write some code for checking checkbox in data controls

<asp:datalist id="DataList1" runat="server" width="70%" onitemcommand="DataList1_ItemCommand" xmlns:asp="#unknown">
          <HeaderTemplate>
              <table width="100%" align="center" border="1">
          </HeaderTemplate>
          <itemtemplate>
              <tr>
                  <td>
                      <asp:checkbox id="CheckBox1" runat="server" />
                  </td>
                  <td>
                      <asp:linkbutton id="LinkButton1" commandname="changepremi" commandargument="<%#Eval("Userid")" runat="server">change</asp:linkbutton>
                  </td>
              </tr>
          </itemtemplate>
          <footertemplate>
              </footertemplate></table>

      </asp:datalist>



文件后面的代码包含以下代码



And code behind file contains following code

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    if (e.CommandName == "changepremi")
    {
        string id = e.CommandArgument.ToString();
        CheckBox chbox = (CheckBox)e.Item.FindControl("CheckBox1");
        if (chbox.Checked)
        {
            // update database
        }
        else
        {
            //update database
        }
    }
}




我希望我的猜测对您的问题是正确的.除了selectedchange事件外,我们无法通过数据控件中的复选框引发数据控制事件.


所有最佳




I hope my guess is right in your question .We cannot raise data control event with checkbox in data control except selectedchange event.


All the Best


都使用模板字段在网格中添加控件
use template field to add controls in grid


< asp:TemplateField HeaderText ="Amount">
< ItemTemplate>
< asp:Label runat =服务器" ID ="Amt"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
根据要求使用不同类型的控件...精细
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:Label runat="server" ID="Amt"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Use different type of control according to the requirment ...Fine


这篇关于gridview中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆