Dynamic GridView

P

pansell

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
 
P

Paulus E Kurniawan

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.
 
P

Paulus E Kurniawan

<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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top