GV Databound Event vs DG ItemDataBound Event

G

GaryDean

It seems every time I try to use the GridView to do what I used to do with
the DataGrid I run into differences that make me want to got back to the
datagrid. for instance...

the DataGrid ItemDataBound event was a very valuable event to customize
binding. We could refer to the item at being bound by referencing
e.item.whatever.

Now with the GridView there is a "DataBound" event but item is no longer a
property! In fact there are no prooperties in the event arguments so we
cannot say e.item. there are just four methods (Equals,GetHashCode,GetType,
and ToString). So how can we reference an item? the documentation is
silent on this - unlike the 1.1 datagrid documentation.

Are there any discussions anywhere on how to do things with the Gridview
that used to be so easy with the DataGrid?

(one of our developers posted on this issue and someone responded that we
should use e.row but there is no row property.)
 
W

Walter Wang [MSFT]

Hi Gary,

Glad to work with you on this GridView question again.

You need to use the RowDataBound event. The DataBound event is fired when
the data binding is completed.

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int productID = (int)DataBinder.Eval(e.Row.DataItem,
"ProductID");
string productName = (string)DataBinder.Eval(e.Row.DataItem,
"ProductName");
}
}

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top