 |
| ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 11th, 2005, 03:37 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
DataGrid dropdownlist in EditItemTemplate
Hello all,
I have place a dropdownlist with some values in the EditItemTemplate of my datagrid(AutoPostBack = True).
<asp:datagrid id=dg1 style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 8px" runat="server" OnItemDataBound="ComputeSum" ShowFooter="True" DataMember="Inventory" DataSource="<%# DsInventory1 %>" GridLines="Horizontal" CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#E7E7FF">
<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:TemplateColumn HeaderText="Test Template Column">
<EditItemTemplate>
<asp:DropDownList id="ddl1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlSelectionChanged">
<asp:ListItem Value="1">One</asp:ListItem>
<asp:ListItem Value="2">Two</asp:ListItem>
<asp:ListItem Value="3">Three</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
I have also add this to the HTML of the EditItemeTemplate
OnSelectedIndexChanged="ddlSelectionChanged"
In my code behind I define the procedure
Protected Sub ddlSelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl As DropDownList
ddl = CType(sender, DropDownList)
Label1.Text = ddl.SelectedItem.Text
End Sub
When I put a row into edit mode, and select a different value in my dropdownlist, the autopostback happens. However, my ddlSelectionChanged sub does not fire. Does anyone know why? What am I missing or doing wrong? As you can see I want to grab the changed value and display it in a label.
Thanks,
Jim
|
|

May 11th, 2005, 03:58 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Where are you binding your data? In Page_Load?
If so, make sure you only bind when PostBack is not true:
If Not Page.IsPostBack Then
' Bind data here
End If
You probably wipe out your drop-down by rebinding it on every page load....
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Dying Slowly by Tindersticks (Track 1 from the album: Can our love...) What's This?
|
|

May 11th, 2005, 11:15 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Thanks for the response however this is not my problem. The data is entered in the collections class of the control.
The problem is that when the selection is changed in the dropdown list, the event I created does not fire.
|
|

May 12th, 2005, 01:01 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Without seeing the rest of the code, the situation could still apply.
When you rebind the parent on post back, the drop down control is overwritten as well. Thus you loose the old selected index and thus SelectedIndexChanged will never fire.
Can you post some more code?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

May 12th, 2005, 08:41 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Again the data is NOT bound. All the code is posted. If this could be the problem, then I will bind the data. But is should not matter I think.
|
|

May 12th, 2005, 08:59 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Jim,
Perhaps Imar means the binding for the datagrid. We see that you have explicitly defined asp:listitem tags for the DDL. However, at some point that grid has to be bound. I haven't often set a datasource in the markup attributes for a grid, I usually bind such controls in code behind.
Is it possible that the grid data is being loaded every time the page runs and/or the grid is being bound every time? When you set an attribute data source, I'm not sure where the bind actually occurs. I assume that somewhere along the line, ASP.NET calls the page's DataBind method which then processes those <%# ...%> databind tags.
Please tell us more about the "DsInventory1" variable and how it is being populated.
- Peter
|
|

May 12th, 2005, 09:22 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Imar, sorry, I was not understanding what you meant in your reply. Thanks to Peter I see you were referring to the DG not the DDL.
Your response was correct! This was a quick test page and I forgot to use If Not IsPostBack Then and that is why I hardcoded some DDL values.
Thanks again Imar and Peter!!!!!
|
|

May 12th, 2005, 11:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
No problem. I could have clarified what binding code I was referring to.
Anyway, glad it's working now.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |