Jump to content

Container.dataitem Does Not Work


soona

Recommended Posts

Hi,i have one gridview . i want to display a Amount column on gridview with datas from database.Please check where i made a mistake in my below code.Because of i cannot see datas on grid view.But, it showing this error messages "Unable to cast object of type 'System.Data.DataRowView' to type 'Main.Details.Item'.i don't know this error message was link with in GridView. <asp:GridView ID="Grid1" runat="server"><Columns> <asp:TemplateField HeaderText="Amount"> <ItemTemplate> <asp:Label ID="Amount" runat="server" Text='<%# Eval('Amount')%>'></asp:Label> </ItemTemplate> </asp:TemplateField></Columns></asp:GridView>con.Open();SqlDataAdapter adapter = new SqlDataAdapter("select Amount from Detail,con);DataSet ds = new DataSet("Detail");myAdapter.Fill(ds, "Detail");Grid1.DataSource = ds;Grid1.DataBind();con.Close();Please can anyone tell how can i clear this error message and how can i display my Amount on gridview?Many thanks

Link to comment
Share on other sites

Rather than:

<asp:Label ID="Amount" runat="server" Text='<%# Eval('Amount')%>'></asp:Label>

You might try something like:

<asp:Label ID="Amount" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Amount") %>'></asp:Label>

If that doesn't work - if you get an error message that says something like "malformed server tag" - you might try this instead:

<asp:Label ID="Amount" runat="server"><%# DataBinder.Eval(Container.DataItem, "Amount") %></asp:Label>

Link to comment
Share on other sites

Hi,i have one gridview . i want to display a Amount column on gridview with datas from database.Please check where i made a mistake in my below code.Because of i cannot see datas on grid view.But, it showing this error messages "Unable to cast object of type 'System.Data.DataRowView' to type 'Main.Details.Item'.i don't know this error message was link with in GridView. <asp:GridView ID="Grid1" runat="server"><Columns> <asp:TemplateField HeaderText="Amount"> <ItemTemplate> <asp:Label ID="Amount" runat="server" Text='<%# Eval('Amount')%>'></asp:Label> </ItemTemplate> </asp:TemplateField></Columns></asp:GridView>con.Open();SqlDataAdapter adapter = new SqlDataAdapter("select Amount from Detail",con);DataSet ds = new DataSet("Detail");myAdapter.Fill(ds,"Detail");Grid1.DataSource = ds;Grid1.DataBind();con.Close();Please can anyone tell how can i clear this error message and how can i display my Amount on gridview?Many thanks
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...