Hi,

I have a dropdown list that is populated with table names from my
database using SqlDataSource1. When I change the selected index I can
get the table name back from the dropdown and display it in a label.

What I want to do is display the data from the table selected in the
dropdown in the GridView control but I have no idea how to do it. So
basically everytime the user selects a different table from the
dropdown the data is displayed in the GridView. The columns in each of
the tables could be different.

I used to do this kind of thing all the time in ASP, but can't work
out the way or approach to do this.

I'm using Framework 2.0, VS Express 2008 and SQL Server 2000.

Many Thanks
Paul

RE: Dynamic GridView by paulusevan

paulusevan
Wed Mar 12 20:18:02 CDT 2008

Paul,

Set the AutoPostBack property of the DropDownList to True, then handle the
SelectedIndexChanged event. In the event handler method, you can pass in the
selected table name as a parameter to your business logic/data access class,
then bind the returned data to the GridView.

If you are using ObjectDataSource with the GridView, create a
ControlParameter object in your SelectParameters collection:

<SelectParameters>
<asp:ControlParameter Name="Table" ControlID="DropDownList1"
PropertyName="Text" />
</SelectParameters>

Hope this helps.
--
Paulus E Kurniawan
http://www.paulusevan.net


"pansell@douc.com" wrote:

> Hi,
>
> I have a dropdown list that is populated with table names from my
> database using SqlDataSource1. When I change the selected index I can
> get the table name back from the dropdown and display it in a label.
>
> What I want to do is display the data from the table selected in the
> dropdown in the GridView control but I have no idea how to do it. So
> basically everytime the user selects a different table from the
> dropdown the data is displayed in the GridView. The columns in each of
> the tables could be different.
>
> I used to do this kind of thing all the time in ASP, but can't work
> out the way or approach to do this.
>
> I'm using Framework 2.0, VS Express 2008 and SQL Server 2000.
>
> Many Thanks
> Paul
>

RE: Dynamic GridView by paulusevan

paulusevan
Wed Mar 12 20:38:01 CDT 2008

> <SelectParameters>
> <asp:ControlParameter Name="Table" ControlID="DropDownList1"
> PropertyName="Text" />
> </SelectParameters>

Specify the type for the ControlParameter to create a strongly typed
parameter:

<SelectParameters>
<asp:ControlParameter Name="Table" ControlID="DropDownList1"
PropertyName="Text" Type="String" />
</SelectParameters>
--
Paulus E Kurniawan
http://www.paulusevan.net


"Paulus E Kurniawan" wrote:

> Paul,
>
> Set the AutoPostBack property of the DropDownList to True, then handle the
> SelectedIndexChanged event. In the event handler method, you can pass in the
> selected table name as a parameter to your business logic/data access class,
> then bind the returned data to the GridView.
>
> If you are using ObjectDataSource with the GridView, create a
> ControlParameter object in your SelectParameters collection:
>
> <SelectParameters>
> <asp:ControlParameter Name="Table" ControlID="DropDownList1"
> PropertyName="Text" />
> </SelectParameters>
>
> Hope this helps.
> --
> Paulus E Kurniawan
> http://www.paulusevan.net
>
>
> "pansell@douc.com" wrote:
>
> > Hi,
> >
> > I have a dropdown list that is populated with table names from my
> > database using SqlDataSource1. When I change the selected index I can
> > get the table name back from the dropdown and display it in a label.
> >
> > What I want to do is display the data from the table selected in the
> > dropdown in the GridView control but I have no idea how to do it. So
> > basically everytime the user selects a different table from the
> > dropdown the data is displayed in the GridView. The columns in each of
> > the tables could be different.
> >
> > I used to do this kind of thing all the time in ASP, but can't work
> > out the way or approach to do this.
> >
> > I'm using Framework 2.0, VS Express 2008 and SQL Server 2000.
> >
> > Many Thanks
> > Paul
> >