J
JJ297
How do I bind three dropdowns on the same page with one gridview.
Here's my source code:
<aspropDownList ID="DropDownList2" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource2"
DataTextField="description"
DataValueField="classificationid"
OnSelectedIndexChanged="dropdownlist2_selectedIndexchanged">
<asp:ListItem>Select a Title</asp:ListItem>
</aspropDownList> <span style="color: #ff3300"><strong>
</strong></span></td>
<aspropDownList ID="DropDownList1" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="Title" DataValueField="Titleid" Height="995px"
Width="400px">
</aspropDownList><br />
<aspropDownList ID="DropDownList3" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource3"
DataTextField="description"
DataValueField="mediaid">
</aspropDownList></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
Here's my source code:
<aspropDownList ID="DropDownList2" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource2"
DataTextField="description"
DataValueField="classificationid"
OnSelectedIndexChanged="dropdownlist2_selectedIndexchanged">
<asp:ListItem>Select a Title</asp:ListItem>
</aspropDownList> <span style="color: #ff3300"><strong>
</strong></span></td>
<aspropDownList ID="DropDownList1" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="Title" DataValueField="Titleid" Height="995px"
Width="400px">
</aspropDownList><br />
<aspropDownList ID="DropDownList3" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource3"
DataTextField="description"
DataValueField="mediaid">
</aspropDownList></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