Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropDownList in Datagrid Footer 1

Status
Not open for further replies.

vwhite

Programmer
Oct 4, 2001
87
AU
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
 
Honestly, I don't see how their example can be working either. If you think about it, each time the grid is bound that function will be called, in essnace, overwriting the selectedindexchanged event's code of the first ddl.

Jim
 
hi again!

Yeah thought that too, but they have a demo that seems to work.

So I have taken out

DataSource='<%#GetUnitsByOutput(-1)%>'

and the ddlOutput_add_SelectedIndexChanged works as expected.

But where can I put
ddlOutputUnit_add.DataSource = GetUnitsByOutput(-1)
so that the drop down list is initially populated?

Vicky....

"I used to have a handle on life...then it broke
 
this is what I have ended up doing....

on page_load

If not IsPostBack then

Dim intFooterIndx as int32 = dgOutputs.Controls(0).Controls.Count - 1
Dim ddlOutput_add as DropDownList = dgOutputs.Controls(0).Controls(intFooterIndx).FindControl("ddlOutput_add")
Dim ddlOutputUnit_add as DropDownList = dgOutputs.Controls(0).Controls(intFooterIndx).FindControl("ddlOutputUnit_add")

Dim intOutputID as Int32 = ddlOutput_add.SelectedItem.Value

ddlOutputUnit_add.DataSource = GetUnitsByOutput(intOutputID)
ddlOutputUnit_add.DataBind()

end if


and this seems to be working....

i may be getting the hang of this....or then again maybe not....!

thanks again ...

Vicky....

"I used to have a handle on life...then it broke
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top