ASP.NET FormView: "Object of type 'System.Int32' cannot be converted to type 'System.String"
Posted
by Vinzcent
on Stack Overflow
See other posts from Stack Overflow
or by Vinzcent
Published on 2010-05-21T14:54:24Z
Indexed on
2010/05/21
15:00 UTC
Read the original article
Hit count: 434
Hey
I have a problem with my FromView. I would like to show some data from a Database Table in my FormView. But some data is from the tupe Int32, while this data should be in a TextBox, a string.
How do you convert these Int32's.
FormView and my ObjectDataSource
<asp:FormView ID="fvDetailOrder" runat="server">
<ItemTemplate>
Aantal:<br />
<asp:Label CssClass="txtBox" ID="Label15" runat="server" Text='<%# Eval("COUNT") %>' /><br />
Prijs:<br />
<asp:Label CssClass="txtBox" ID="Label16" runat="server" Text='<%# Eval("PRICE") %>' /><br />
Korting:<br />
<asp:Label CssClass="txtBox" ID="Label17" runat="server" Text='' /><br />
Totaal:<br />
<asp:Label CssClass="txtBox" ID="Label18" runat="server" Text='<%# Eval("AMOUNT") %>' /><br />
Betaald:<br />
<asp:Label CssClass="txtBox" ID="Label19" runat="server" Text='<%# Eval("PAID") %>' /><br />
Datum betaling:<br />
<asp:Label CssClass="txtBox" ID="Label20" runat="server" Text='<%# Eval("PDATE") %>' /><br />
</ItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="objdsOrderID" runat="server"
OnSelecting="objdsOrderID_Selecting" SelectMethod="getOrdersByID"
TypeName="DAL.OrdersDAL">
<SelectParameters>
<asp:Parameter Name="id" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
My Code behind
protected void gvOrdersAdmin_SelectedIndexChanged(object sender, EventArgs e)
{
fvDetailOrder.DataSource = objdsOrderID;
fvDetailOrder.DataBind(); // <-- HERE I GET THE ERROR
}
protected void objdsOrderID_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters["id"] = gvOrdersAdmin.DataKeys[gvOrdersAdmin.SelectedRow.RowIndex].Values[0]; ;
}
My Data Acces Layer
public static DataTable getOrdersByID(string id)
{
string sql = "SELECT 'AUTHOR' = tblAuthors.FIRSTNAME + ' ' + tblAuthors.LASTNAME, tblBooks.*, tblGenres.*, tblLanguages.*, tblOrders.* FROM tblAuthors INNER JOIN tblBooks ON tblAuthors.AUTHOR_ID = tblBooks.AUTHOR_ID INNER JOIN tblGenres ON tblBooks.GENRE_ID = tblGenres.GENRE_ID INNER JOIN tblLanguages ON tblBooks.LANG_ID = tblLanguages.LANG_ID INNER JOIN tblOrders ON tblBooks.BOOK_ID = tblOrders.BOOK_ID"
+ " WHERE tblOrders.ID = @id;";
SqlDataAdapter da = new SqlDataAdapter(sql, GetConnectionString());
da.SelectCommand.Parameters["id"].Value = id;
DataSet ds = new DataSet();
da.Fill(ds, "Orders");
return ds.Tables["Orders"];
}
Thanks a lot, Vincent
© Stack Overflow or respective owner