DroDownlist in DataGrid produces Error
Posted
by
S Nash
on Stack Overflow
See other posts from Stack Overflow
or by S Nash
Published on 2013-06-28T16:07:39Z
Indexed on
2013/06/28
16:21 UTC
Read the original article
Hit count: 301
I have a DataGrid and everytime I change value of it's embeded dropdwonlist I get: "System.Web.HttpException: The IListSource does not contain any data sources."
I have a data grid which loads fine:
Name column is editable. I have a dropdownlist these :
DataDataGrid gets its value from a table.
(Select Name, Address From Persons)
Dropdown list also gets list of names from the same table.
So DataGrid and dropdownlist are bound to 2 different datasets.
Here is my code for dataGrid"
<Columns>
<ASP:ButtonColumn Text="Delete" CommandName="Delete"></ASP:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<ASP:TemplateColumn HeaderText="Name" SortExpression="FY" HeaderStyle-HorizontalAlign="center" HeaderStyle-Wrap="True">
<ItemStyle Wrap="false" HorizontalAlign="left" />
<ItemTemplate>
<ASP:Label ID="Name" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' runat="server"/>
</ItemTemplate>
<EditItemTemplate>
<ASP:DropDownList id="ddlName" cssClass="DropDownList" runat="server" datasource="<%#allNames%>" DataTextField= "Name" DataValueField="ID" Defaultvalue='<%# DataBinder.Eval(Container.DataItem, "ID") %>' OnPreRender="SetDefaultListItem" accessKey="I" AutoPostBack="true" />
</EditItemTemplate>
</ASP:TemplateColumn>
<asp:BoundColumn DataField="Address" ReadOnly="True" HeaderText="Address"></asp:BoundColumn>
</Columns>
Error happens here :
dg.DataSource = ds
dg.DataBind()
Any ideas how to solve this issues? All I want is a DataGrid with a editable column ,which can be edited by choosing one of the value of in a dropdownlist.
© Stack Overflow or respective owner