ASP.Net GridView Drillthrough

Associate
Joined
25 Feb 2007
Posts
905
Location
Midlands
Hi All,

I have a GridView in my webapp which displays data from a SQL datasource. The datasource is set via code (as opposed to the markup - apologies if my terminology is incorrect).

What I'd like to be able to do is when the user clicks on data in the row, the GridView datasource changes based on what was clicked, and the GridView updated to show the new data.

This may not be the best way to do this and if so I'm open to suggestions. Ultimately I need to be able to 'drillthrough' from the initial data to display a breakdown of the selected row.

How could I do this? This is in C#.

Thanks :D,
 
Linq to SQL is a massive "You should really, really not use it" failure of a framework. It's outdated, deprecated, unfinished, and generally awful. Even the authors at MS have been known to say "Don't use it."

Its successor is the Microsoft Entity Framework (MEF) which is better. There are other options besides, such as NHibernate, which I personally think is better still.

Besides which - this is all irrelevant. The OP doesn't need to know it, necessarily. They need to learn about events on the GridView instance, and perhaps (without purposely being derisive to the OP) even more "beginner to ASP" topics such as understanding the ASP lifecycle.

OP, please post what you think needs to happen - i.e. the code you have so far - and it will be marginally easier for others to help.
 
Thanks for the replies both.

I'm creating a dataset from a SQL query and binding this to the GridView (should I not be using this?), by setting the GridView's datasource to be the above dataset and then using GridView.DataBind().

Bit of background to what I'm trying to achieve - I'm trying to replicate a Reporting Services report (because it needs to be cleverer than SSRS will allow e.g. filtering the report based on the user logged in, aslong as that user is part of a certain AD group etc.) The report I'm trying to replicate allows the user to click on the numerical values and links to another report which shows a breakdown of the value clicked.

For example:

Report 1 shows -

Vegetables 10
Fruit 6
Other 4

Clicking on '10' takes you to Report 2, which shows -

Lettuce 3
Carrots 2
Onions 5

Therefore, I was thinking that I need to use some sort of OnClick/RowClick event of the GridView, but it doesn't seem to have these? To make it seemless, I was hoping to just update the SQL query (which is a string) and run GridView.DataBind() again, although I'm not sure if that would work?

As I said, if there is a better way to achieve this, I'm open to suggestions! :D
 
My example:

protected void gridView_Databound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onClick"] = "location.href='view.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "id") + "'";
}
}

Stelly
 
I did something similar to what you describe on a job a few years ago.

The approach I took was to make a field a hyperlink in the row, and when clicked, it would open a new instance of the page in a new window with the drilldown data. This was just another database call with a separate query on the database. It used the value passed into the hyperlink call as a parameter for the query e.g. mysite.com/mypage.aspx?myVar=123

This is probably the wrong way to go about it but it worked well for us. It was an internal app and was rushed due to time constraints but it might help.

Link to a thread about it: http://forums.asp.net/t/1111431.aspx/1

Edit: basically what stelly said above.
 
Back
Top Bottom