Datagrid footer template dropdown list problem
Hi,
I have a datagrid with footer contains two dropdown lists. When first dropdown list selected, second dropdown should populate from the database. I have the problem with second dropdown list.It's not populating the data.I tried to debug the code.It found the 'Footer template' control and also the database query is working fine.
Here is the code. Could you please help.
Regards..
<asp:datagrid id="dgCust" runat="server"
AutoGenerateColumns="False"
OnItemCommand="dg_Insert"
ShowFooter="True"
<Columns>
---
<FooterTemplate>
<asp:DropDownList runat="server" id="lstMaster"
DataValueField="ID" DataTextField="cust_Name"
DataSource='<%# GetList() %>'
AutoPostBack="True"
OnSelectedIndexChanged="PopulateSecondList" />
</FooterTemplate>
</asp:TemplateColumn>
<FooterTemplate>
<asp:DropDownList runat="server" id="lstDetails"
DataValueField="ID" DataTextField="Location"
DataSource='<%# GetSecondList(-1) %>' />
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Code behind file
-----------------------
Sub PopulateSecondList(sender as Object, e as EventArgs)
Dim Master as DropDownList = sender
Dim dgDetail as DataGridItem = Master.Parent.Parent
Dim test as DropDownList = dgDetail.FindControl("lstDetails")
Dim cID as Integer = Master.SelectedItem.Value
test .DataSource = GetSecondList(cID)
test .DataBind()
End Sub
---------------
Function GetSecondList(cID as Integer) as DataTable
Dim sql as String
sql = "SELECT id, location, description from test where id =" & cID
Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(sql, myConnection)
myDataAdapter.Fill(myDataSet, "SAT")
Return myDataSet.Tables("SAT")
End Function
|