Datagrid error with inline dropdown list
Hi,
This is my first post to the Wrox forums, and I was hoping that somebody could help with a problem.
I have a DropDownList that is within a Datagrid. The list is populated from a database table, and I would like to set the selectedindex according to the value stored for each row.
The idea is that it will be possible to change the value on each row using the dropdown of valid values.
However, I am getting the error
'System.Web.UI.WebControls.DataGridItem.DataItem' denotes a 'property' where a 'method' was expected
The problem is being caused by the line:
SelectedIndex='<%# GetSelIndex(Container.DataItem("TypeID")) %>'
Here is my code...
DataSet GetTypes()
{
SqlConnection SqlCon = new SqlConnection(ConnectionString);
SqlDataAdapter SqlDa = new SqlDataAdapter("SELECT * FROM IncidentType", SqlCon);
DataSet ds = new DataSet();
SqlDa.Fill(ds);
return ds;
}
.
.
.
.
.
.
<asp:DataGrid AutoGenerateColumns="false" ID="incident" runat="server">
<Columns>
<asp:BoundColumn DataField="IncidentID" HeaderText="ID" />
<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList
AutoPostBack="true"
DataSource="<%# GetTypes() %>"
HeaderText="ID"
DataValueField="TypeID"
DataTextField="TypeDesc"
SelectedIndex='<%# GetSelIndex(Container.DataItem("TypeID")) %>'
ID="ItemDropDown"
OnSelectedIndexChanged="Update_Type_ID"
Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="SummaryDesc" HeaderText="Summary" />
Many Thanks
|