+ Reply to Thread
Results 1 to 2 of 2

Thread: Finding Datalist Row on auto postback

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Finding Datalist Row on auto postback

    This is a bit of a complicated one and I can't quite figure out how to approach it.

    I have a datalist that shows data in dropdowns and text boxes. They are all contained within table cells that runat the server to enable me to toggle the visibility easily.

    The first cell has a dropdown that controls what other dropdowns and text boxes should be shown in that row. What I want to do is when this dropdown is changed do an autopostback which will toggle the visibility of the other table cells within that row.

    My problem is when the dropdown is changed and posts back, how do I know which datalist item the dropdown come from? In addition, how do I then find the controls within the datalist that I need to change?

    The other related issue is I have a button that allows users to add another item to the datalist, based on the same format. This is contained within the footer of the datalist, so it always appears at the bottom of the current list. When they click the button another row appears (the footer) just showing the first column dropdown (this bit works fine). When they make a selection, I want the footer to show the correct dropdowns and textboxes based on the selection made.

    Again, how can I tell that it is the footer dropdown that has been changed and then how can I find the relevant controls to allow me to toggle the visibility of the various cells I need to hide/show?

    Here's the datalist code:-
    Code:
    <asp:datalist ID="dlst_premiums" runat="server" OnUpdateCommand="butt_show_add_premium" OnItemDataBound="dlst_premiums_onitemdatabound">
    
    <ItemTemplate>
    <tr>
    <td id="td_source_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8">Source</td>
    <td id="td_transfer_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8">Transfer from</td>
    <td id="td_premium_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8">Premium</td>
    <td id="td_frequency_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8">Frequency</td>
    <td id="td_premiumtype_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8">Type</td>
    <td id="td_level_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8">Level/Incr</td>
    <td id="td_incrby_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8">By</td>
    <td id="td_status_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8">Status</td>
    </tr>
    <tr>
    <td id="td_source" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8">
    <asp:DropDownList ID="ddl_source" runat="server" CssClass="registerform7" OnSelectedIndexChanged="change_premium_source" />
    </td>
    <td id="td_transfer" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8">
    <asp:DropDownList ID="ddl_transfer" runat="server" CssClass="registerform7" />
    </td>
    <td id="td_premium" runat="server" align="center" style="padding:1px 2px 1px 2px;" class="dblue8">
    £<asp:textbox ID="txt_premium" runat="server" MaxLength="20" Width="80px" CssClass="registerform7" />
    </td>
    <td id="td_frequency" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8">
    <asp:DropDownList ID="ddl_frequency" runat="server" CssClass="registerform7">
    <asp:ListItem Text="Please Select" Value="" />
    <asp:ListItem Text="Monthly" />
    <asp:ListItem Text="Annually" />
    <asp:ListItem Text="Quarterly" />
    </asp:DropDownList>
    </td>
    <td id="td_premiumtype" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8">
    <asp:DropDownList ID="ddl_premiumtype" runat="server" CssClass="registerform7" />
    </td>
    <td id="td_level" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8">
    <asp:DropDownList ID="ddl_level" runat="server" CssClass="registerform7">
    <asp:ListItem Text="Level" Value="lev" />
    <asp:ListItem Text="Increasing" Value="inc" />
    </asp:DropDownList>
    </td>
    <td id="td_incrby" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8">
    <asp:textbox ID="txt_incrby" runat="server" MaxLength="3" Width="20px" CssClass="registerform7" />
    </td>
    <td id="td_status" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8">
    <asp:DropDownList ID="ddl_status" runat="server" CssClass="registerform7" />
    </td>
    </tr>
    </ItemTemplate>
     
    <FooterTemplate>
    <tr id="tr_addpremium_h" runat="server">
    <td id="td_add" runat="server" style="padding:8px 0px 2px 5px;" class="dblue8"><asp:ImageButton ID="butt_showadd" runat="server" ImageUrl="link_add1.gif" ToolTip="Click to add a premium" CommandName="Update" /></td>
    <td id="td_source_h_add" runat="server" style="text-align:center;padding:1px 2px 1px 2px;width:10%;" class="dblue8" visible="false">Source</td>
    <td id="td_transfer_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8" visible="false">Transfer from</td>
    <td id="td_premium_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8" visible="false">Premium</td>
    <td id="td_frequency_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8" visible="false">Frequency</td>
    <td id="td_premiumtype_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8" visible="false">Type</td>
    <td id="td_level_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8" visible="false">Level/Incr</td>
    <td id="td_incrby_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8" visible="false">By</td>
    <td id="td_status_h" runat="server" style="text-align:center;padding:1px 2px 1px 2px;" class="dblue8" visible="false">Status</td>
    </tr>
    <tr id="tr_addpremium" runat="server" visible="false">
    <td id="td_source_add" runat="server" style="padding:1px 2px 1px 2px;width:10%;" class="dblue8" visible="false">
    <asp:DropDownList ID="ddl_source_add" runat="server" CssClass="registerform7" AutoPostBack="true" OnSelectedIndexChanged="change_premium_source" />
    </td>
    <td id="td_transfer" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8" visible="false">
    <asp:DropDownList ID="ddl_transfer_add" runat="server" CssClass="registerform7" />
    </td>
    <td id="td_premium" runat="server" align="center" style="padding:1px 2px 1px 2px;" class="dblue8" visible="false">
    £<asp:textbox ID="txt_premium_add" runat="server" MaxLength="20" Width="80px" CssClass="registerform7" />
    </td>
    <td id="td_frequency" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8" visible="false">
    <asp:DropDownList ID="ddl_frequency_add" runat="server" CssClass="registerform7">
    <asp:ListItem Text="Please Select" Value="" />
    <asp:ListItem Text="Monthly" />
    <asp:ListItem Text="Annually" />
    <asp:ListItem Text="Quarterly" />
    </asp:DropDownList>
    </td>
    <td id="td_premiumtype" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8" visible="false">
    <asp:DropDownList ID="ddl_premiumtype_add" runat="server" CssClass="registerform7" />
    </td>
    <td id="td_level" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8" visible="false">
    <asp:DropDownList ID="ddl_level_add" runat="server" CssClass="registerform7">
    <asp:ListItem Text="Level" Value="lev" />
    <asp:ListItem Text="Increasing" Value="inc" />
    </asp:DropDownList>
    </td>
    <td id="td_incrby" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8" visible="false">
    <asp:textbox ID="txt_incrby_add" runat="server" MaxLength="3" Width="20px" CssClass="registerform7" />
    </td>
    <td id="td_status" runat="server" style="padding:1px 2px 1px 2px;" class="dblue8" visible="false">
    <asp:DropDownList ID="ddl_status_add" runat="server" CssClass="registerform7" />
    </td>
    </tr>
    </FooterTemplate>
    </asp:datalist>
    
    The 2 dropdowns I've highlighted are the first column ones. When these are changed, I need to know which row (or footer) of the datalist they're from and then know how to access the controls within that row.

    Hope that all makes sense....

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Think I've worked out a solution.

    In the OnSelectedIndexChanged event, declare the dropdownlist as an object and then use the .parent method to go back up to the datalist item control.

    Code:
    Sub change_ddl_level(ByVal s As Object, ByVal e As EventArgs)
            Dim ddl_id As DropDownList = s
            Dim dlst_item As DataListItem = s.parent.parent 'this finds the datalist item
            Dim td_incrby_h As HtmlTableCell = dlst_item.FindControl("td_incrby_h")
            Dim td_incrby As HtmlTableCell = dlst_item.FindControl("td_incrby")
            If ddl_id.SelectedValue = "inc" Then
                td_incrby_h.Visible = True
                td_incrby.Visible = True
            Else
                td_incrby_h.Visible = False
                td_incrby.Visible = False
            End If
    End Sub
    

+ Reply to Thread

Similar Threads

  1. Using AJAX Auto Complete Extender with Database
    By richyrich in forum .NET Code Samples
    Replies: 0
    Last Post: March 26th, 2008, 08:59 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

SEO by vBSEO