如何检查是否从GridView中选择了任何行?
我在aspx页面中有一个gridview:
--- No Consumer Exists ---
rowDataBound
方法是:
protected void gdvMainList_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gdvMainList, "Select$" + e.Row.RowIndex); } }
我有一个OK按钮,当它被点击时,我从页面收集数据。 我想查看OK按钮单击是否有任何从Gridview中选择的行。
我怎样才能做到这一点? 任何帮助,将不胜感激。
你可以检查…
if (GridView1.SelectedValue != null) { //Row is Selected }
你可以尝试这样的事情:
If GridView1.SelectedRows.Count > 0 Then ' yourcode here - a row is selected Else ' yourcode here - NO row is selected End If
更好的是:
if(GridView1.SelectedIndex < 0) { its -1 and no row is selected.} else {its >= 0 and a row is selected}
如果所选值为!= null
则测试!= null
将抛出exception。
你也可以这样检查
上述就是C#学习教程:如何检查是否从GridView中选择了任何行?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)
if(GridView.SelectedIndex >= 0) { string result = "Selected"; } else { string result = "Not Selected"; }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。
如若转载,请注明出处:https://www.ctvol.com/cdevelopment/1027288.html