Binding 3 dropdowns with 1 gridview

J

JJ297

How do I bind three dropdowns on the same page with one gridview.

Here's my source code:

<asp:DropDownList ID="DropDownList2" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource2"
DataTextField="description"
DataValueField="classificationid"
OnSelectedIndexChanged="dropdownlist2_selectedIndexchanged">
<asp:ListItem>Select a Title</asp:ListItem>
</asp:DropDownList>&nbsp; <span style="color: #ff3300"><strong>
</strong></span></td>

<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="Title" DataValueField="Titleid" Height="995px"
Width="400px">
</asp:DropDownList><br />

<asp:DropDownList ID="DropDownList3" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource3"
DataTextField="description"
DataValueField="mediaid">
</asp:DropDownList></td>

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="classificationid"
HorizontalAlign="Center" Width="584px" AllowPaging="True"
PageSize="20">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title"
SortExpression="Title" />
<asp:BoundField DataField="descriptions"
HeaderText="descriptions" SortExpression="descriptions" />
<asp:BoundField DataField="description"
HeaderText="description" SortExpression="description" />
<asp:BoundField DataField="classificationid"
HeaderText="classificationid" InsertVisible="False"
ReadOnly="True" SortExpression="classificationid" />
</Columns>
</asp:GridView>

Here's the code behind:

Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DropDownList2.SelectedIndexChanged
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("UserConnectionString").ConnectionString)

Dim cmd As New Data.SqlClient.SqlCommand
With cmd
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "Getclassifications1"

.Parameters.AddWithValue("classificationid",
DropDownList2.SelectedValue)
.Connection = conn

End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmd)
Try

conn.Open()

Dim ds As New Data.DataSet
adapter.Fill(ds)

GridView1.DataSource = ds

GridView1.DataBind()

Finally

conn.Close()

End Try

End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("UserConnectionString").ConnectionString)

Dim cmd As New Data.SqlClient.SqlCommand
With cmd
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "GetTitlesForResourceLibrary"

.Parameters.AddWithValue("Titleid",
DropDownList1.SelectedValue)
.Connection = conn

End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmd)
Try

conn.Open()

Dim ds As New Data.DataSet
adapter.Fill(ds)

GridView1.DataSource = ds

GridView1.DataBind()

Finally

conn.Close()

End Try


End Sub

Protected Sub DropDownList3_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DropDownList3.SelectedIndexChanged
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("UserConnectionString").ConnectionString)

Dim cmd As New Data.SqlClient.SqlCommand
With cmd
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "GetMediaType"

.Parameters.AddWithValue("Mediaid",
DropDownList3.SelectedValue)
.Connection = conn

End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmd)
Try

conn.Open()

Dim ds As New Data.DataSet
adapter.Fill(ds)

GridView1.DataSource = ds

GridView1.DataBind()

Finally

conn.Close()

End Try

End Sub
End Class
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top