I fixed this by changing my table layout to match the control property I am
binding to. For example, I returned a tinyint column and tried to bind it to
the SelectedIndex property of a dropdownlist. When i changed the column to
an int, the databinding worked. The question is - how do you convert the
value returned in a databinder statement? I can't figure it out but I'm new
with C#.
[quoted text, click to view] > SelectedIndex='<%#DataBinder.Eval(Container.DataItem, "ddlOper")%>'>
"Tim_k" wrote:
> Hi,
> I have a dropdown control as a template column in a datagrid on an asp page.
> I bind the datagrid to a dataset. My code worked in VB but in C# I get an
> error "specified cast is not valid" on the datagrid.bind. Can anyone give me
> a suggestion? I tried to cast the DataBinder.Eval to (DropDownList) but that
> didn't work. I'm new to C# so any help is greatly appreciated.
> Thanks,
> Tim
>
> <asp:TemplateColumn HeaderText="Operator"><ItemTemplate>
> <asp:DropDownList id=ddlOper runat="server" Width="68px" Font-Size="Smaller"
> SelectedIndex='<%#DataBinder.Eval(Container.DataItem, "ddlOper")%>'>
> <asp:ListItem Value="0" Selected="True">=</asp:ListItem>
> <asp:ListItem Value="1"><</asp:ListItem>
> </asp:DropDownList> </ItemTemplate></asp:TemplateColumn>
>
> C# code:
> string strSQL = "SELECT ddlOper, .... FROM CountsDetail";
> dsCountsDetail = CreateDataSet( strSQL); // returns dataset
> System.Web.UI.WebControls.DataGrid transTemp3 = dgQuery;
> transTemp3.DataSource = dsCountsDetail;
> transTemp3.DataBind();
> transTemp3.Visible = true;