This problem is driving me to distraction.
I have a datagrid that has the footer enabled to add data to datagrid. I have 2 dropdownlists in the footer, one of which is dependent on the other.
To implement this I have the first Dropdown as follows:
<footertemplate>
<asp:dropdownlist runat="server" id="ddlOutput_add" CssClass="DDL_STYLE"
DataValueField="ACTIVITY_ID"
DataTextField="ACTIVITY"
DataSource="<%# GetOutputs() %>"
Visible="true" Width="300"
AutoPostBack="true"
OnSelectedIndexChanged="ddlOutput_add_SelectedIndexChanged"/>
</footertemplate>
the second drop down is as follows
<footertemplate>
<asp:dropdownlist runat="server" id="ddlOutputUnit_add" CssClass="DDL_STYLE" Width="100"
DataValueField="UNIT_ID"
DataTextField="UNIT"
DataSource='<%#GetUnitsByOutput(-1)%>' />
</footertemplate>
and here are the functions :
Sub ddlOutput_add_SelectedIndexChanged(sender as Object, e as EventArgs)
Dim ddlOutput_add as DropDownList = Sender
Dim dgi as DataGriditem = ddlOutput_add.parent.parent
Dim ddlOutputUnit_add as DropDownList = dgi.FindControl("ddlOutputUnit_add")
Dim outputID as Int32 = ddlOutput_add.SelectedItem.Value
ddlOutputUnit_add.DataSource = GetUnitsByOutput(outputID)
ddlOutputUnit_add.DataBind()
End Sub
Private Function GetUnitsByOutput(OutputID as Int32) as Dataset
m_dsOutputUnits = New Dataset()
Dim strSQL as string
ConnectDB()
if OutputID < 0 then
strSQL = "SELECT * FROM LKP_SMU_ACTIVITY_UNIT_TBL_qry WHERE ACTIVITY_ID = " & _
"(SELECT TOP 1 ACTIVITY_ID FROM LKP_SMU_OUTCOMES_ACTIVITY_TBL_qry WHERE OUTCOME_ID = "& ddlOutcome.SelectedValue & ")"
else
strSQL = "SELECT * FROM LKP_SMU_ACTIVITY_UNIT_TBL_qry WHERE ACTIVITY_ID = " & OutputID
End if
Dim da as oledbDataAdapter = New oledbDataadapter(strSQL, m_objConn)
da.Fill(m_dsOutputUnits, "LKP_SMU_ACTIVITY_UNIT_TBL_qry")
DisconnectDB()
Return m_dsOutputUnits
End Function
When the footer is first displayed - the ddlOutputUnit_add dropdownlist displays the value based on the first value in the ddlOutput_add DropDownList as expected.
The trouble is when the ddlOutput_add value is changed the SelectedIndexChanged Event fires and sets the correct DataSource for ddlOutputUnit_add, but then the DataSource='<%#GetUnitsByOutput(-1)%>' is fired again.
I am following an example from 4 Guys from Rolla
and there it seems to work perfectly.
Can any body see what I have done wrong??
thanks
Vicky....
"I used to have a handle on life...then it broke
I have a datagrid that has the footer enabled to add data to datagrid. I have 2 dropdownlists in the footer, one of which is dependent on the other.
To implement this I have the first Dropdown as follows:
<footertemplate>
<asp:dropdownlist runat="server" id="ddlOutput_add" CssClass="DDL_STYLE"
DataValueField="ACTIVITY_ID"
DataTextField="ACTIVITY"
DataSource="<%# GetOutputs() %>"
Visible="true" Width="300"
AutoPostBack="true"
OnSelectedIndexChanged="ddlOutput_add_SelectedIndexChanged"/>
</footertemplate>
the second drop down is as follows
<footertemplate>
<asp:dropdownlist runat="server" id="ddlOutputUnit_add" CssClass="DDL_STYLE" Width="100"
DataValueField="UNIT_ID"
DataTextField="UNIT"
DataSource='<%#GetUnitsByOutput(-1)%>' />
</footertemplate>
and here are the functions :
Sub ddlOutput_add_SelectedIndexChanged(sender as Object, e as EventArgs)
Dim ddlOutput_add as DropDownList = Sender
Dim dgi as DataGriditem = ddlOutput_add.parent.parent
Dim ddlOutputUnit_add as DropDownList = dgi.FindControl("ddlOutputUnit_add")
Dim outputID as Int32 = ddlOutput_add.SelectedItem.Value
ddlOutputUnit_add.DataSource = GetUnitsByOutput(outputID)
ddlOutputUnit_add.DataBind()
End Sub
Private Function GetUnitsByOutput(OutputID as Int32) as Dataset
m_dsOutputUnits = New Dataset()
Dim strSQL as string
ConnectDB()
if OutputID < 0 then
strSQL = "SELECT * FROM LKP_SMU_ACTIVITY_UNIT_TBL_qry WHERE ACTIVITY_ID = " & _
"(SELECT TOP 1 ACTIVITY_ID FROM LKP_SMU_OUTCOMES_ACTIVITY_TBL_qry WHERE OUTCOME_ID = "& ddlOutcome.SelectedValue & ")"
else
strSQL = "SELECT * FROM LKP_SMU_ACTIVITY_UNIT_TBL_qry WHERE ACTIVITY_ID = " & OutputID
End if
Dim da as oledbDataAdapter = New oledbDataadapter(strSQL, m_objConn)
da.Fill(m_dsOutputUnits, "LKP_SMU_ACTIVITY_UNIT_TBL_qry")
DisconnectDB()
Return m_dsOutputUnits
End Function
When the footer is first displayed - the ddlOutputUnit_add dropdownlist displays the value based on the first value in the ddlOutput_add DropDownList as expected.
The trouble is when the ddlOutput_add value is changed the SelectedIndexChanged Event fires and sets the correct DataSource for ddlOutputUnit_add, but then the DataSource='<%#GetUnitsByOutput(-1)%>' is fired again.
I am following an example from 4 Guys from Rolla
and there it seems to work perfectly.
Can any body see what I have done wrong??
thanks
Vicky....
"I used to have a handle on life...then it broke