Results 1 to 2 of 2

Thread: Datagrid: Catching multiple Control values on Dropdownlist selection

  1. #1
    Join Date
    Jun 2004

    Datagrid: Catching multiple Control values on Dropdownlist selection

    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>


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

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




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

    <asp:TemplateColumn HeaderText="Grafico">


    <aspropDownList 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>




    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!!!

    PS = Sorry for bad quoting ^_^''

  2. #2
    Join Date
    Jan 2005
    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:

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center