Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Dropdownlist and edititem template


Message #1 by "T Wade" <twade@f...> on Thu, 6 Jun 2002 19:07:32
With the following code I'm trying to use a dropdownlist which is only 
avaiable at edit time. Now the dropdownlist works when you click edit from 
the datagrid.

My problem is, getting the selected item back into the .aspx.cs code. I've 
tried setting a protype in the class protect system.......dropdownlist 
DaySelected;

I've tried addressing the dropdownlist directly - it is not available to 
the aspx.cs code.

I've tried creating the dropdownlist inside the aspx.cs code but the html 
does not see it.

All I need to do, is create a dropdownlist at runtime which I can connect 
to the edititem template and get the selected value into a field or value 
which I can store in a database field. You don't have to make my method 
work if you know of another way please let me know.

Thank you in advance
Thomas


<asp:TemplateColumn HeaderText="Block Day">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.BdayText") %>'></asp:Label>
</ItemTemplate>

<EditItemTemplate>
<asp:DropDownList runat=server AutoPostBack=True 
OnSelectedIndexChanged="UpdateBday" ID=DaySelected >
<asp:ListItem Selected=True></asp:ListItem>
<asp:ListItem Value=Mon>Mon</asp:ListItem>
<asp:ListItem Value=Tue>Tue</asp:ListItem>
<asp:ListItem Value=Wes>Wes</asp:ListItem>
<asp:ListItem Value=Thu>Thu</asp:ListItem>
<asp:ListItem Value=Fri>Fri</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Thu, 6 Jun 2002 14:57:55 -0400
Thomas,

	I've put many DropDownList controls into EditItemTemplates, and
they've worked fine.  I think what you're missing here is the FindControl.
You'll want to do something like this (I'm assuming you've linked an event
to handle updates, I will call it UpdateCommand here):

protected void
yourDataGrid_UpdateCommand(System.Web.UI.WebControls.DataGridCommandEventArg
s e)
{
	someValue 
((DropDownList)e.Item.FindControl("yourDropDownListId")).SelectedItem.Value;
	// now someValue has the value of the selected item in your
	// drop down list
}

HTH,
- Chuck

-----Original Message-----
From: T Wade [mailto:twade@f...]
Sent: Thursday, June 06, 2002 3:08 PM
To: ASP+
Subject: [aspx] Dropdownlist and edititem template


With the following code I'm trying to use a dropdownlist which is only 
avaiable at edit time. Now the dropdownlist works when you click edit from 
the datagrid.

My problem is, getting the selected item back into the .aspx.cs code. I've 
tried setting a protype in the class protect system.......dropdownlist 
DaySelected;

I've tried addressing the dropdownlist directly - it is not available to 
the aspx.cs code.

I've tried creating the dropdownlist inside the aspx.cs code but the html 
does not see it.

All I need to do, is create a dropdownlist at runtime which I can connect 
to the edititem template and get the selected value into a field or value 
which I can store in a database field. You don't have to make my method 
work if you know of another way please let me know.

Thank you in advance
Thomas


<asp:TemplateColumn HeaderText="Block Day">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.BdayText") %>'></asp:Label>
</ItemTemplate>

<EditItemTemplate>
<asp:DropDownList runat=server AutoPostBack=True 
OnSelectedIndexChanged="UpdateBday" ID=DaySelected >
<asp:ListItem Selected=True></asp:ListItem>
<asp:ListItem Value=Mon>Mon</asp:ListItem>
<asp:ListItem Value=Tue>Tue</asp:ListItem>
<asp:ListItem Value=Wes>Wes</asp:ListItem>
<asp:ListItem Value=Thu>Thu</asp:ListItem>
<asp:ListItem Value=Fri>Fri</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
Message #3 by "Patterson, Stephanie L" <stephanie.l.patterson@i...> on Thu, 6 Jun 2002 12:53:09 -0700
I'm looking to do the same thing and am having trouble.  Unfortunately, I
don't know C#. How do you do this in VB?

In advance, thanks for the help!
Stephanie

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Thursday, June 06, 2002 11:58 AM
To: ASP+
Subject: [aspx] RE: Dropdownlist and edititem template


Thomas,

	I've put many DropDownList controls into EditItemTemplates, and
they've worked fine.  I think what you're missing here is the FindControl.
You'll want to do something like this (I'm assuming you've linked an event
to handle updates, I will call it UpdateCommand here):

protected void
yourDataGrid_UpdateCommand(System.Web.UI.WebControls.DataGridCommandEventArg
s e)
{
	someValue 
((DropDownList)e.Item.FindControl("yourDropDownListId")).SelectedItem.Value;
	// now someValue has the value of the selected item in your
	// drop down list
}

HTH,
- Chuck

-----Original Message-----
From: T Wade [mailto:twade@f...]
Sent: Thursday, June 06, 2002 3:08 PM
To: ASP+
Subject: [aspx] Dropdownlist and edititem template


With the following code I'm trying to use a dropdownlist which is only 
avaiable at edit time. Now the dropdownlist works when you click edit from 
the datagrid.

My problem is, getting the selected item back into the .aspx.cs code. I've 
tried setting a protype in the class protect system.......dropdownlist 
DaySelected;

I've tried addressing the dropdownlist directly - it is not available to 
the aspx.cs code.

I've tried creating the dropdownlist inside the aspx.cs code but the html 
does not see it.

All I need to do, is create a dropdownlist at runtime which I can connect 
to the edititem template and get the selected value into a field or value 
which I can store in a database field. You don't have to make my method 
work if you know of another way please let me know.

Thank you in advance
Thomas


<asp:TemplateColumn HeaderText="Block Day">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.BdayText") %>'></asp:Label>
</ItemTemplate>

<EditItemTemplate>
<asp:DropDownList runat=server AutoPostBack=True 
OnSelectedIndexChanged="UpdateBday" ID=DaySelected >
<asp:ListItem Selected=True></asp:ListItem>
<asp:ListItem Value=Mon>Mon</asp:ListItem>
<asp:ListItem Value=Tue>Tue</asp:ListItem>
<asp:ListItem Value=Wes>Wes</asp:ListItem>
<asp:ListItem Value=Thu>Thu</asp:ListItem>
<asp:ListItem Value=Fri>Fri</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>


  Return to Index