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

Discussion in 'ASP .Net Datagrid Control' started by Steve Myers, Nov 18, 2003.

  1. Steve Myers

    Steve Myers Guest

    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("SchedulePeriod")) %>'
    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, Nov 18, 2003
    #1
    1. Advertising

  2. Steve Myers

    MSFT Guest

    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).FindControl("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! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    MSFT, Nov 19, 2003
    #2
    1. Advertising

  3. Steve Myers

    Steve Myers Guest

    Thanks! That worked perfectly!


    (MSFT) wrote in message news:<>...
    > 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).FindControl("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! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
     
    Steve Myers, Nov 20, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vishnu
    Replies:
    1
    Views:
    1,251
    Patrick.O.Ige
    Mar 25, 2006
  2. Replies:
    2
    Views:
    459
  3. Frank Kurka
    Replies:
    8
    Views:
    342
  4. Jaime Stuardo

    GridView control enters edit mode when I click Edit link twice

    Jaime Stuardo, Apr 7, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    450
    Jaime Stuardo
    Apr 7, 2006
  5. jobs at webdos
    Replies:
    0
    Views:
    522
    jobs at webdos
    Oct 9, 2006
Loading...

Share This Page