How can I get the GridView object in the RowDataBound event?

M

mark4asp

I have two grid views on the page and I want them to share the same
RowDataBound event.

In debug mode in notice that sender and gvMandates (below) are both
termed {System.Web.UI.WebControls.GridView} when I add a watch and
that they show more or less the same properties and methods (depending
upon whether they are the same gridview). However when coding using
intellisense gvMandates shows all the properties and methods available
to it while sender has only 4 methods, equals(), GetHashCode(),
GetType(), ToString(). Further, if I substitute sender for gvMandates
in the code, compilation fails.

protected void GridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Text = "<a href='javascript:InflowDetails("
+ gvMandates.DataKeys[e.Row.DataItemIndex].Value + ");'>"
+ e.Row.Cells[0].Text + "</a>";
sender.
}
}

This is not just a moan for consistency but also a plea. How can find
out what the actual GridView object is? Do I really need to make a
GridView object up (see below) or is there a more elegant way I could
do this?

protected void GridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gv = (sender.Equals(gvMandates)) ? gvMandates :
gvMandateTotals;
e.Row.Cells[0].Text = "<a href='javascript:InflowDetails(" +
gv.DataKeys[e.Row.DataItemIndex].Value + ");'>" + e.Row.Cells[0].Text
+ "</a>";
}
}
 

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

Similar Threads


Top