Datagrid: Catching multiple Control values on Dropdownlist selection

liunx

Guest
Hi to all,

I've a problem... this is the situation:

In a Datagrid I have a column reporting an ID in a control Label


<asp:TemplateColumn Visible="False">

<HeaderStyle HorizontalAlign="Left"></HeaderStyle>

<ItemTemplate>

<asp:Label id="lblID" runat="server" EnableViewState="True" Visible="False" >

<%# DataBinder.Eval(Container.DataItem, "ID") %>

</asp:Label>

</ItemTemplate>

</asp:TemplateColumn>


Then, in the last column of the datagrid, I've a dropdownlist, reporting interval values
as ListItem... let's say:


<asp:TemplateColumn HeaderText="Grafico">

<ItemTemplate>

<asp:DropDownList id="MonthDropDown" AutoPostBack="True" Runat="server" CssClass="combos" OnSelectedIndexChanged="ddlMese_SelectedIndexChanged">

<asp:ListItem Value="1">1 Mese</asp:ListItem>

<asp:ListItem Value="3">3 months</asp:ListItem>

<asp:ListItem Value="6">6 months</asp:ListItem>

<asp:ListItem Value="12">12 months</asp:ListItem>

</asp:DropDownList>

</ItemTemplate>

</asp:TemplateColumn>


*****************************
The problem is, that I've to redirect the user to another page when he selects a value
in the dropdownlist, also bringin the ID of the first field.

In codebehind I use:


Protected Sub ddlMese_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)



Dim ddlMonth As DropDownList = CType(sender, DropDownList)

Dim dgi As DataGridItem = CType(ddlMonth.Parent.Parent, DataGridItem)

Dim ChoosenMonth As DropDownList = CType(dgi.FindControl("MonthDropDown"), DropDownList)



' this one should contain the value but it's always empty!!! **********

Dim id As Label = CType(dgi.FindControl("lblID"), Label)

'*********************************************************



Response.Redirect("dettInd.aspx?per=" & MeseScelto.SelectedItem.Value & "&tfs=" & id.Text)



End Sub


A final note... I don't understand why the value of the dropdownlist it's catched, but
all seem correct...the label is founded ... but the text of the label is always empty!!
Please, if anyone has any clue it would be really appreciated...thanks a lot!!!
Simone

PS = Sorry for bad quoting ^_^''That sounds like a lot of complexity. Are you doing in-line editing? it may be more user-friendly to just have an 'Edit' column and put all the data input on one page.

As far as retrieving values goes, I think the problem is here:CType(dgi.FindControl("lblID"), Label)I'm still trying to figure this out, but I believe FindControl only looks at the current level (it doesn't drill down). So your code is searching the DataGrid for your label. All the datagrid returns is a bunch of Items, Cells, Rows, and Columns. Try digging down manually: dgi.Items[x].Cells[y].FindControl("lblID")
-Chris
 
Back
Top