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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a dropdownvalue for other dropdownlist in a editable datalist

Status
Not open for further replies.

adrian0605

Programmer
Apr 3, 2007
10
0
0
RO
Hi,

I'm trying to get a value from a dropdownlist(ddl1) to use as a parameter in another dropdownlist(ddl2), in same editable datalist.

<edititempemplate>

<asp:DropDownList id="ddl1" runat="server">
<asp:ListItem Text="xxxxxx" Value="1" />
</asp:DropDownList>


<asp:DropDownList id="ddl2" runat="server" datavaluefield="LoID" datatextfield="LoID" DataSource="<%# TempDataView2 %>" />

</editimtemplate>

Code behind:


Private Sub dlClient_EditCommand(...)

PopulateDropDownList2()

dlInfogen.EditItemIndex = e.Item.ItemIndex
getClients()

End Sub

Sub PopulateDropDownList2()

Dim TempList2 As DropDonwlist = CType(FindControl("ddl1"), DropDownList)
Dim Temval as string = TempList2.SelectedItem.Value

Dim dataAdapter2 As SqlDataAdapter

dataAdapter2 = New SqlDataAdapter("GetLoc", objConn)
dataAdapter2.SelectCommand.CommandType = CommandType.StoredProcedure
dataAdapter2.SelectCommand.Parameters.Add("@JID", SqlDbType.Int).Value = Temval

dataAdapter2.Fill(objDS, "Loc")
TempDataView2 = objDS.Tables("Loc").DefaultView
End Sub

My problem is that I get an error "Object reference not set to an instance of an object.".
Semms that I can't get the value from ddl1, using FindControl.

Can somebody tell me where I'm wrong?
 
It doesn't ind the control, because you are in the Page object when you are doing FindConrol. You need to find the control when you are in an event related to the datalist, like rowdatabound, or something like that.
 
Thanks for reply, but even when is on Item created I can't find selected value...
 
Even in the ItemDataBound still can't the value of the first dropdown.
I use the follwing sintax:

Dim TempVal as string = CType(e.item.FindControl("ddl1"), dropDownList).SelectedItem.value

 
you need to post the HTML and your codebehind for us to look at
 
OK.

<asp:DataList DataKeyField="ClientID" ID="dlInfogen" CssClass="datalist111" Runat="server">
<ItemTemplate>
<asp:LinkButton CommandName="Edit" CausesValidation="False" Font-Size="12px" CssClass="linkEdi" ID="Linkbutton4" runat="server" Text="Edit" />

</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList AutoPostBack="True" ID="ddl1" Runat="server" CssClass="ddlist">
<asp:ListItem Value="1" />
<asp:ListItem Value="2" />
<asp:ListItem Value="3" />
<asp:ListItem Value="4" />
</asp:DropDownList>
<br /><br />

<asp:DropDownList id="ddl2" CssClass="ddlist" runat="server" datavaluefield="LoID" datatextfield="Client" DataSource="<%# TempDataView2 %>"> </asp:DropDownList>


Code behind


Private Sub dlInfogen_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlInfogen.EditCommand
dlInfogen.EditItemIndex = e.Item.ItemIndex
getClient2()

End Sub

Private Sub dlInfogen_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlInfogen.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim TempList2 As String = CType(e.Item.FindControl("ddlJud"), DropDownList).SelectedItem.Value

Dim dataAdapter2 As SqlDataAdapter

dataAdapter2 = New SqlDataAdapter("GetClienti", objConn)
dataAdapter2.SelectCommand.CommandType = CommandType.StoredProcedure
dataAdapter2.SelectCommand.Parameters.Add("@JID", SqlDbType.Int).Value = TempList2
dataAdapter2.Fill(objDS, "Local")
TempDataView2 = objDS.Tables("Local").DefaultView
End If
End Sub


Now if I replace TempList2 with a number, it's ok, but in my example I can't find the value of ddl1.

Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top