vb.net SelectedIndexChanged 事件中的 Gridview FindControl

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15850855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:08:24  来源:igfitidea点击:

Gridview FindControl inside SelectedIndexChanged event

asp.netvb.net

提问by Lord Relix

I created a TemplateFieldin my ASP GridView, and now I want to write a small logic for a checkbox in the gridview. I am trying the FindControlcode to no success, I've used these combinations...

TemplateField在我的 ASP GridView 中创建了一个,现在我想为 gridview 中的复选框编写一个小逻辑。我正在尝试FindControl代码但没有成功,我已经使用了这些组合......

Dim chkChosen As CheckBox = 
'GridView1.Rows(e.RowIndex).FindControl("Checkbox1")
'DirectCast(GridView1.Rows(e.RowIndex).FindControl("Checkbox1"), CheckBox).Value
'chkChosen = (CheckBox)row.FindControl("Checkbox1")

I commented them as I've used a combination of those three to no success. They all give me the same error... "RowIndex is not a Member of SystemArg...". All this is under a SelectedIndexChangedprotected sub.

我对它们进行了评论,因为我将这三者结合使用但没有成功。他们都给了我同样的错误......“RowIndex 不是 SystemArg 的成员......”。所有这些都在SelectedIndexChanged受保护的潜艇之下。

采纳答案by Praveen Nambiar

This should work in your case:

这应该适用于您的情况:

Dim chkChosen As CheckBox = CType(GridView1.SelectedRow.FindControl("Checkbox1"), CheckBox)

回答by Amit Singh

You Can Get By Gridview Selected Row Index..lyk this

您可以通过 Gridview Selected Row Index 获取..lyk 这个

   GridViewRow row = GridView1.Rows[GridView1.SelectedIndex];

cHeckbox chk=row.FindControl("chk");