Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
gopal.panda@gmail.com #1
Unable to get selected values from dropdownlist, present in DataGrid.
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.FindByTe xt(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_SelectedIndexCh anged" DataSource=
"<%# FillDropDown() %>" DataTextField="ImageLocation"
DataValueField="ImageLocation" Runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
gopal.panda@gmail.com Guest
-
Unable to display the data in dropdownlist in datagrid
Hi all, I am unable to display the data in dropdown list in datagrid control. can anybody help me please? my ItemDataBound code is here..... ... -
Unable get Boolean and Numeric values from XLS into Dataset and Datagrid
Hi All I am presently dealing with a project,in which I have to convert an XLS file into XML file. To accomplish this I have used Dataset as... -
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column
i am trying to trap the value of one dropdownlist (in a datagrid edititemtemplate column) at the time its selectedindexchanged event fires and use... -
can't set the selected item of the dropdownlist
I generate template columns in datagrid dynamic and I want dropdownlist in the EditItemTemplate, I did it But I can't set the selected item of... -
problem with dropdownlist selected item
I'm having the problem with this drop down list on postback. For some reason both the ListItems get selected when I change the selected item. Using...



Reply With Quote

