469,568 Members | 1,375 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

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

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>";
}
}

Mar 12 '07 #1
1 12041
just cast the sender as a gridview

-- bruce (sqlwork.com)

mark4asp wrote:
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>";
}
}
Mar 12 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Giovanni | last post: by
5 posts views Thread by sutphinwb | last post: by
6 posts views Thread by Kevin Attard | last post: by
6 posts views Thread by AG | last post: by
4 posts views Thread by =?Utf-8?B?Y2hyaXM=?= | last post: by
3 posts views Thread by tshad | last post: by
1 post views Thread by =?Utf-8?B?cmxt?= | last post: by
17 posts views Thread by ata | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.