开发者

Binding from codebehind (ASP.NET)

I have SqlDataSource assigned to a GridView, and a lot of the fields retur开发者_如何学Cned are only used in the code behind to determine whether a column is visible, etc. Currently I bind these vlaues to a hiddenfield, however this adds a lot of code to the source file which isn't ideal.

Can I get the values for the row from the codebehind, without having to assign them to a hiddenfield in the markup?


In your code behind, you can access the values through the DataItem object

Example

DataRowView rowView = (DataRowView)e.Row.DataItem;

// Retrieve the state value for the current row. 

String state = rowView["state"].ToString();

Or you could convert the value to an object and play around with it.

Take a look here for more info http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewrow.dataitem.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜