Professional Web Applications Themes

Edit Mode - How do I populate dropdown in edittemplate from dropdown in another column? - ASP.NET Data Grid Control

I have a datagrid with 2 columns that I want to interact when I'm in Edit Mode. I've reproduced just the columns I want to interact below. I can get into Edit mode for the selected row just Fine. What I want to do is to have the user select an entry in the editschSchedulePeriod template (options are "D" or "M"). Once the user selects this, I want to execute a subroutine to populate the EditschPeriod edititemtemplate dropdownlist. This dropdownlist will have differing values based on the selection from the first control. Hence I don't want to populate it until ...

  1. #1

    Default Edit Mode - How do I populate dropdown in edittemplate from dropdown in another column?

    I have a datagrid with 2 columns that I want to interact when I'm in
    Edit Mode. I've reproduced just the columns I want to interact below.

    I can get into Edit mode for the selected row just Fine. What I want
    to do is to have the user select an entry in the editschSchedulePeriod
    template (options are "D" or "M"). Once the user selects this, I want
    to execute a subroutine to populate the EditschPeriod edititemtemplate
    dropdownlist. This dropdownlist will have differing values based on
    the selection from the first control. Hence I don't want to populate
    it until the user selects an entry from the first dropdownlist.

    I've tried to add a routine called "PeriodChange" that would execute
    when the OnSelectedIndexChanged event occurs. However, I'm not sure if
    this is the correct approach or if there is a better way.

    I'm having trouble with the logic to access the controls.
    Wonder if someone could help get me started with the logic to access
    this control and populate the second control here.

    thanks!



    <Columns>
    <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
    CancelText="Cancel" EditText="Edit">
    <ItemStyle Wrap="False"></ItemStyle>
    </asp:EditCommandColumn>

    <asp:TemplateColumn SortExpression="SchedulePeriod"
    HeaderText="SchedulePeriod">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <asp:Label runat="server" Text='<%#
    DataBinder.Eval(Container.DataItem, "SchedulePeriod") %>'
    ID="schSchedulePeriod" />
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList runat="server"
    OnSelectedIndexChanged="PeriodChange" SelectedIndex='<%#
    GetSchedulePeriodIndex(Container.DataItem("Schedul ePeriod")) %>'
    id="editschSchedulePeriod">
    <asp:ListItem>D</asp:ListItem>
    <asp:ListItem>M</asp:ListItem>
    </asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn SortExpression="Period" HeaderText="Period">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <asp:Label runat="server" Text='<%#
    DataBinder.Eval(Container.DataItem, "Period") %>' ID="schPeriod" />
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList runat="server" SelectedIndex='<%#
    GetPeriodIndex(Container.DataItem("Period")) %>'
    id="EditschPeriod">
    </asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateColumn>
    </Columns>



    Public Sub PeriodChange(ByVal sender As Object, ByVal e As
    System.EventArgs)


    How do I reference control and set other control here?

    End Sub
    Steve Myers Guest

  2. #2

    Default RE: Edit Mode - How do I populate dropdown in edittemplate from dropdown in another column?

    Hello,

    First you need set the DropDownlist's AutoPostBack to true so that the
    function "PeriodChange" in code behind will be execute after you select a
    item. And then find the second dropdownlist control in the same row and add
    the items to it:


    Public Sub PeriodChange(ByVal sender As System.Object, ByVal e As
    System.EventArgs)

    Dim ddl_schSchedulePeriod As DropDownList = sender

    Dim ddl_schPeriod As DropDownList

    ddl_schPeriod =
    ddl_schSchedulePeriod.Parent.Parent.Controls(2).Fi ndControl("EditschPeriod")


    ddl_schPeriod.Items.Clear()

    If ddl_schSchedulePeriod.SelectedValue = "D" Then
    ddl_schPeriod.Items.Add("D_tiem1")
    ddl_schPeriod.Items.Add("D_tiem2")
    Else
    ddl_schPeriod.Items.Add("M_tiem1")
    ddl_schPeriod.Items.Add("M_tiem2")
    End If


    End Sub

    Hope this help,

    Luke
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    MSFT Guest

  3. #3

    Default Re: Edit Mode - How do I populate dropdown in edittemplate from dropdown in another column?

    Thanks! That worked perfectly!


    [email]lukezhanonline.microsoft.com[/email] (MSFT) wrote in message news:<5X9nimmrDHA.1720cpmsftngxa06.phx.gbl>...
    > Hello,
    >
    > First you need set the DropDownlist's AutoPostBack to true so that the
    > function "PeriodChange" in code behind will be execute after you select a
    > item. And then find the second dropdownlist control in the same row and add
    > the items to it:
    >
    >
    > Public Sub PeriodChange(ByVal sender As System.Object, ByVal e As
    > System.EventArgs)
    >
    > Dim ddl_schSchedulePeriod As DropDownList = sender
    >
    > Dim ddl_schPeriod As DropDownList
    >
    > ddl_schPeriod =
    > ddl_schSchedulePeriod.Parent.Parent.Controls(2).Fi ndControl("EditschPeriod")
    >
    >
    > ddl_schPeriod.Items.Clear()
    >
    > If ddl_schSchedulePeriod.SelectedValue = "D" Then
    > ddl_schPeriod.Items.Add("D_tiem1")
    > ddl_schPeriod.Items.Add("D_tiem2")
    > Else
    > ddl_schPeriod.Items.Add("M_tiem1")
    > ddl_schPeriod.Items.Add("M_tiem2")
    > End If
    >
    >
    > End Sub
    >
    > Hope this help,
    >
    > Luke
    > Microsoft Online Support
    >
    > Get Secure! [url]www.microsoft.com/security[/url]
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    Steve Myers Guest

Similar Threads

  1. Working with a 2 column Dropdown
    By jonefer in forum ASP.NET Building Controls
    Replies: 1
    Last Post: September 11th, 11:57 AM
  2. CSS dropdown menu problem in Edit Mode
    By Gill at VU in forum Macromedia Contribute General Discussion
    Replies: 2
    Last Post: November 1st, 09:45 PM
  3. Edit Datagrid - show textbox and dropdown
    By Anamika in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: April 20th, 10:33 PM
  4. Can't get to nested dropdown in edititemtemplate column
    By Brian Greiwe in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: September 16th, 07:59 PM
  5. Replies: 0
    Last Post: July 7th, 08:32 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139