Welcome to Dream.In.Code
Getting Help is Easy!

Join 131,593 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,972 people online right now. Registration is fast and FREE... Join Now!




DropDowns in DataGrid [RESOLVED]

 
Reply to this topicStart new topic

DropDowns in DataGrid [RESOLVED], DropDown won't populate ASP.net and C#

5thWall
post 6 Oct, 2008 - 07:54 AM
Post #1


New D.I.C Head

*
Joined: 17 Sep, 2008
Posts: 32



Thanked 1 times
My Contributions


Alright I've been beating my head against this one for a while I'm trying to replace the default text box with a DropDownList when I edit a row of a DataGrid. The drop down is present when I hit the edit button, but it isn't populated. What am I doing wrong here?

This is my datagrid
xml

<div id="dish_list">
<asp:DataGrid ID="dgDishList" runat="server" AutoGenerateColumns="false"
CssClass="dataGrid" OnEditCommand="EditDishList" OnCancelCommand="CancelDishEdit"
OnItemDataBound="dgDishList_ItemDataBound">
<HeaderStyle CssClass="HeaderStyle" />
<ItemStyle CssClass="ItemStyle" />
<AlternatingItemStyle CssClass="AlternatingItemStyle" />
<EditItemStyle CssClass="EditItemStyle" />
<Columns>
<asp:BoundColumn DataField="DISH_ORDINAL" HeaderText="#" ReadOnly="true" />
<asp:TemplateColumn HeaderText="Dish Type">
<ItemTemplate>
<asp:Label ID="lblDLDishType" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "dish_type_desc") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlDLDishTypes" runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="DISH_TYPE_DESC" HeaderText="Type" />
<asp:BoundColumn DataField="DISH_NAME" HeaderText="Name" />
<asp:EditCommandColumn HeaderText="Edit" EditText="Edit"
UpdateText="Update" CancelText="Cancel" />
</Columns>
</asp:DataGrid>


And here's my code-behind
csharp

protected void dgDishList_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
Control ctrl = e.Item.FindControl("ddlDGDishList");
if (ctrl != null)
{
DropDownList ddlDishTypes = (DropDownList) ctrl;
ddlDishTypes.DataSource = app.dishTypes();
ddlDishTypes.DataTextField = "dish_type_desc";
ddlDishTypes.DataValueField = "dish_type";
ddlDishTypes.DataBind();
}
}
}


What am I doing wrong?

This post has been edited by 5thWall: 6 Oct, 2008 - 08:32 AM
User is offlineProfile CardPM

Go to the top of the page


5thWall
post 6 Oct, 2008 - 08:33 AM
Post #2


New D.I.C Head

*
Joined: 17 Sep, 2008
Posts: 32



Thanked 1 times
My Contributions


Well if you look at your code you named your DropDownList ddlDLDishTypes, but in your code-behind you called it ddlDGDishTypes so correct either of those and it should work.


Why thank you, that does work.

No problem.


Bah! Why don't I catch my stupid little errors until I ask someone else to look at my code?

This post has been edited by 5thWall: 6 Oct, 2008 - 08:38 AM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 03:54AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month