Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Unable to get selected values from dropdownlist, present in DataGrid.

Thread Tools

Unable to get selected values from dropdownlist, present in DataGrid.
Posts: n/a
I am unable to get the values from a dropdownlist which is present
in Editable Template Column of the datagrid. I am using C# as backend
code. For refrence i am pasting the code snippets.

public void dgBanner_Update(object sender,DataGridCommandEventArgs e)
DropDownList tempDDL =
string txtTemp = ((TextBox)(e.Item.FindControl("txtImageId"))).Text ;
string tempSelected = tempDDL.SelectedItem.Value;
public void dgBanner_Edit(object sender, DataGridCommandEventArgs E)
dgBanner.EditItemIndex = System.Convert.ToInt32(E.Item.ItemIndex);
strCurrentLocation =
((Label)(E.Item.FindControl("lblImageLocation"))). Text.ToUpper();

public void dgBanner_ItemDataBound(object sender, DataGridItemEventArgs
if (e.Item.ItemType == ListItemType.EditItem)
DropDownList myDropDown = null;
myDropDown = (DropDownList)(e.Item.FindControl("ddLocation"));
myDropDown.SelectedIndex =
myDropDown.Items.IndexOf(myDropDown.Items.FindByTe xt(strCurrentLocation));


<asp:datagrid id="dgBanner" runat="server" Width="70%"
AllowPaging="True" CssClass="alt1Active"autogeneratecolumns="False"
OnEditCommand="dgBanner_Edit" OnItemDataBound="dgBanner_ItemDataBound"
OnCancelCommand="dgBanner_Cancel" OnUpdateCommand="dgBanner_Update">
<asp:TemplateColumn HeaderText="Image Location">
<ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
<asp:Label ID="lblImageLocation" Text='<%#
DataBinder.Eval(Container.DataItem, "ImageLocation")%>' Runat="server"
<asp:TextBox id="txtImageId" Visible="False"
Text='<%#DataBinder.Eval(Container.DataItem, "ImageId")
<asp:Label ID="lblEditImageLocation" Text='<%#
DataBinder.Eval(Container.DataItem, "ImageLocation")%>' Runat="server"
<aspropDownList ID="ddLocation"
OnSelectedIndexChanged="ddLocation_SelectedIndexCh anged" DataSource=
"<%# FillDropDown() %>" DataTextField="ImageLocation"
DataValueField="ImageLocation" Runat="server">

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
OS present but not present. XPD NZ Computing 4 04-11-2007 11:22 PM
Unable to get the selected item value of Listbox in codebehind akula.sandeepkumar ASP .Net 0 11-02-2006 01:04 PM
In Menu Control's item collection, setting .Selected=false doesn't work if children present Wayne Erfling ASP .Net 0 10-13-2006 01:24 PM
unable to get selected value of listbox control when clicking button? Joey ASP .Net 2 08-04-2004 02:09 PM
Schema: express that "@a present if and only if @b present", where @a, @b are attributes Ralf Wahner XML 5 12-24-2003 11:37 AM