473,320 Members | 1,914 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,320 software developers and data experts.

GridView help please...

I hope I can explain this clearly enough to get help.

I have three gridviews that need to work from each other to
display like a java verticle menu (just in the way it appears).
GridView1 is fine with this code:
<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1"
DataKeyNames="id"
autogenerateselectbutton="True"
autogeneratecolumns="False"
onSelectedIndexChanged="getSelected" GridLines="Horizontal"
HorizontalAlign="Left">
<columns>
<asp:boundfield headertext="name" datafield="name" />
<asp:BoundField HeaderText="" />
</Columns>
<SelectedRowStyle BackColor="AliceBlue" />
<AlternatingRowStyle BackColor="AliceBlue" />
</asp:GridView>

protected void getSelected(Object id, EventArgs e)
{
string name1 = GridView1.SelectedDataKey.Value.ToString();
string query = "Select name FROM categories where parent_id =
'" + name1 + "'";
GridView2.DataSource = CreateDataSet(query, null);
GridView2.DataBind();
}

If I define the DataKeyNames='id' in GridView2, I get this error:

DataBinding: 'System.Data.DataRowView' does not contain a property
with
the name 'id'.

So I put it in right after the onSelectedIndexChanged (not in the
control itself):
GridView2.DataKeyNames = new string[] { "id" };

Since I'm not calling a datasource until the gridview is displayed,
I have to write the code this way:

<asp:GridView ID="GridView2" runat="server"
DataSourceID=""
autogenerateselectbutton="True"
autogeneratecolumns="False"
onSelectedIndexChanged="getSelected2" GridLines="Horizontal"
HorizontalAlign="Left">
<columns>
<asp:boundfield headertext="name" datafield="name" />
<asp:BoundField />
</Columns>
<SelectedRowStyle BackColor="AliceBlue" />
<AlternatingRowStyle BackColor="AliceBlue" />
</asp:GridView>

protected void getSelected2(Object id, EventArgs e)
{
GridView2.DataKeyNames = new string[] { "id" };
string name2 = GridView2.SelectedDataKey.Value.ToString();
string query = "Select name FROM categories where parent_id =
'" + name2 + "'";
//GridView2.DataKeyField = "id";
GridView3.DataSource = CreateDataSet(query, null);
GridView3.DataBind();
//planDetails.DataSource = fetchData(query, "plans");
//planDetails.DataBind();
//ShowHidePanel(null, null);
}

But, after GridView2 is displayed, I can't get a selection to
work without this error:

Object reference not set to an instance of an object on this line
: string name2 = GridView2.SelectedDataKey.Value.ToString();

Any help is appreciated.
Thanks,
Trint

Mar 12 '07 #1
0 1497

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
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...
8
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the wizards. Basically working as expected. The...
2
by: cartmann | last post by:
Hi, I have a gridview with a template column. In the template column i have two commandbuttons. When clicking the buttons I enter the cmd_click event - but how do I read in which row the button...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
4
by: Tomasz | last post by:
Hello Developers, Here is interesting problem I just came across: how do I wire a GridView control programmatically? Here is my sample code using Object Data Source: protected void...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
4
by: Peter | last post by:
I want to call a JavaScript on PageIndexChanged event, how do I do that? Thank You Peter
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.