一个BoundField的GridView控件获取值设置为可见=假 [英] Gridview getting value of a BoundField set to Visible=False

查看:264
本文介绍了一个BoundField的GridView控件获取值设置为可见=假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能被设置为可见=虚假的字段的值?如下:

How can i get the value of a field that is set to Visible=false? as follows:

 <asp:BoundField DataField="ItemID" HeaderText="Line Item ID" Visible="false"/> 



但是当我尝试用

but when i try to get it with

 int temID = Convert.ToInt32(row.Cells[0].Text);



它不能找到它,并抛出一个异常,但如果我使其可见=真它的工作原理

It cant find it and throws an exception, but if I make it Visible="true" it works.

我怎样才能检索该值如果可见=假的?

How can I retrieve the value if visible = false?

推荐答案

在你的GridView的定义,添加

In the definition of your GridView, add

<asp:GridView .... DataKeyNames="ItemID" ...>

您还需要使用OnRowDataBound,不OnDataBound

You also need to use OnRowDataBound, not OnDataBound

<asp:GridView .... DataKeyNames="ItemID" ... OnRowDataBound="GridView_RowDataBound">

在你的代码背后,像这样

Then in your code behind, something like this

protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
     if(e.Row.RowType == DataControlRowType.DataRow)
     {
          int ItemId = Int32.Parse(YourGridView.DataKeys[e.Row.RowIndex].Values[0].ToString());
     }
}



我没有发布之前测试此代码。但是,这是你需要做的的总体思路。它可能会或可能无法正常工作是

I did not test this code before posting. But this is the general idea of what you need to do. It may or may not work as is.

这篇关于一个BoundField的GridView控件获取值设置为可见=假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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