Unable to get selected values from dropdownlist, present in DataGrid.

G

gopal.panda

Hi,
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 =
(DropDownList)(e.Item.FindControl("ddLocation"));
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();
FillGrid();
}

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

HERE GOES THE ASP.NET CODE SNIPPETS.

<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">
<Columns>
<asp:TemplateColumn HeaderText="Image Location">
<ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblImageLocation" Text='<%#
DataBinder.Eval(Container.DataItem, "ImageLocation")%>' Runat="server"
/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtImageId" Visible="False"
Text='<%#DataBinder.Eval(Container.DataItem, "ImageId")
%>'runat="server"/>
<asp:Label ID="lblEditImageLocation" Text='<%#
DataBinder.Eval(Container.DataItem, "ImageLocation")%>' Runat="server"
/>
<asp:DropDownList ID="ddLocation"
OnSelectedIndexChanged="ddLocation_SelectedIndexChanged" DataSource=
"<%# FillDropDown() %>" DataTextField="ImageLocation"
DataValueField="ImageLocation" Runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top