I have the following code that is throwing this error but the solutions I've found say, "Have you tried the DataSourceID instead of DataSource?" with no indication as to what should be used for the DataSourceID value.
<Columns>
<asp:BoundColumn DataField="id" SortExpression="id" HeaderText="ID" ItemStyle-CssClass="dgCells"></asp:BoundColumn>
<asp:BoundColumn DataField="first_name" SortExpression="first_name" HeaderText="First" ItemStyle-CssClass="dgCells"></asp:BoundColumn>
<asp:BoundColumn DataField="last_name" SortExpression="last_name" HeaderText="Last" ItemStyle-CssClass="dgCells"></asp:BoundColumn>
<asp:BoundColumn DataField="login_pw" HeaderText="Password" ItemStyle-CssClass="dgCells"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Race">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "race_name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" id="ddlRaces" DataValueField="race_id" DataTextField="race_name" >>>DataSourceID=""<<< />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Ok"></asp:EditCommandColumn>
</Columns>
What I should be inserting into the DataSourceID="" value?
The DataSourceID
should be set to the ID of a control on your page that inherits from DatasourceControl
such as SqlDatasource
if you want to populate the grid from an SQL database
To bind the DropDown in a GridView
protected void GV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
var ddl = (DropDownList)item.FindControl("ddlRaces");
ddl.Datasource = GetRaces();
ddl.DataBind();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With