如何在GridView中获取复选框(注意:复选框没有ID)?! [英] How To Get CheckBox In GridView (Note:CheckBox Dont Have ID)?!!

查看:78
本文介绍了如何在GridView中获取复选框(注意:复选框没有ID)?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我在GridView中有CheckBox,但不知道如何在服务器端获取它?
我需要CommandArgument之类的东西
请帮助我
谢谢


不能选择Faiulre

hi all
I have CheckBox Inside GridView and I Dont Know how To get It in Server Side?
i Need Something like CommandArgument
Please Help me
Thanks


Faiulre Is Not An Option

推荐答案

检查本文.我已经解释了如何在服务器端获取它.

www.c-sharpcorner.com/UploadFile/1a81c5/non -editable-fields-in-Asp-Net-gridview/ [
Check this article. I have explained how to get it in server side.

www.c-sharpcorner.com/UploadFile/1a81c5/non-editable-fields-in-Asp-Net-gridview/[^]


protected void grvPGIS_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
           CheckBox chk= (CheckBox )e.Row.FindControl("CheckBoxID");
           
        }
    }


取决于您要查找的位置,可以在RowCommand RowDataBound 或其他任何位置.在RowCommand RowDataBound 中,您可以尝试将e.Item强制转换为DataRow.如果您想在其他情况下获取它,请尝试遍历它,并使用FindControl函数查找带有ID的复选框.
试试这个:
Depends on where you wanna find, either in RowCommand or RowDataBound or anywhere else. In RowCommand and RowDataBound you can try casting e.Item as your DataRow. If you want to get it in other event try looping through it and use FindControl function to find your checkbox with the id.
Try this:
foreach(var item in GridView1.Items)
{
     CheckBox chk=(CheckBox)item.FindControl("CheckBox1");
     //Do your job here.
}



在gridview事件中,尝试使用e.Item.FindControl("CheckBox1"),但请确保e.Item是您的gridview DataItem.


--Amit



In the gridview events try using e.Item.FindControl("CheckBox1") but make sure that e.Item is your gridview DataItem.


--Amit


这篇关于如何在GridView中获取复选框(注意:复选框没有ID)?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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