473,396 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 12174
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
5
by: maurban | last post by:
Hi there experts, I have a gridview with a couple textboxes and a dropdownlist. I'm trying to insert a default value into my database driven dropdownlist. I'm doing this in the rowdatabound...
6
by: AG | last post by:
I have a gridview with a template column containing an imagebutton to delete the row. Under some condition I don't want the row to be deleted, so would like to remove the button. In the...
4
by: =?Utf-8?B?Y2hyaXM=?= | last post by:
I have a perent gridview which includes in a template field a child gridview. Child gridview includes command buttons for opening different windows based on its row selected. I used the code...
3
by: tshad | last post by:
I am building a GridView that is displaying some money values in 3 columns. I want to put the totals of each column in a label field (one for each column) in the footer. I was trying to figure...
1
by: =?Utf-8?B?cmxt?= | last post by:
I have standard gridview in an updatePanel with an AJAX timer that refreshes the data every 5 seconds by calling the grids DataBind method in the tick event. This works great. However, I have a...
17
by: ata | last post by:
Hi folks, Consider a gridview that's being bound to a ObjectDataSource that uses an adapter to handle data access logic. 1. How am I supposed to have a RowIndex column *without* modifying the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.