472,982 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 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 1469

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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.