且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

gridview中的复选框

更新时间:2022-12-02 21:14:48



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

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