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

S

Steve Myers

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
 
M

MSFT

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top