TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sreepathy s prabhu
NA
217
101.1k
Unable to cast object of type 'System.Web.UI.LiteralControl'
May 3 2015 11:51 PM
Unable to cast object of type 'System.Web.UI.LiteralControl' error on quantity,amount
protected void gdShoppingCart_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
bool result;
ShopingCartBLL cartObj = new ShopingCartBLL();
TextBox txtId = (TextBox)(gdShoppingCart.Rows[e.RowIndex].Cells[0].Controls[0]);
cartObj.BookId = Convert.ToInt32(txtId.Text);
TextBox txtTitle = (TextBox)(gdShoppingCart.Rows[e.RowIndex].Cells[1].Controls[0]);
cartObj.Title = txtTitle.Text;
TextBox txtPrice = (TextBox)(gdShoppingCart.Rows[e.RowIndex].Cells[2].Controls[0]);
cartObj.Price = Convert.ToDouble(txtPrice.Text);
TextBox txtQuantity = (TextBox)(gdShoppingCart.Rows[e.RowIndex].Cells[3].Controls[0]);
cartObj.Quantity =Convert.ToInt32(txtQuantity.Text);
TextBox txtAmount = (TextBox)(gdShoppingCart.Rows[e.RowIndex].Cells[4].Controls[0]);
cartObj.Amount = Convert.ToDouble(txtAmount.Text);
cartObj.UserId = 2;//replace it with session or pass url
result = cartObj.UpdateAnItem();
if (result)
{
string script = "<script>alert('UpDated')</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UpDated", script);
gdShoppingCart.EditIndex = -1;
BindData();
}
else
{
string script = "<script>alert('UpDated Failed')</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UpDated", script);
}
}
<Columns>
<asp:BoundField DataField="boo_id" HeaderText="ID" />
<asp:BoundField DataField="boo_title" HeaderText="Title" />
<asp:BoundField DataField="car_price" HeaderText="Price" />
<asp:TemplateField HeaderText="Quantity">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("car_quantity") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("car_quantity") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblShipping" runat="server" Text="Shipping"></asp:Label>
<br />
<asp:Label ID="lblTotalAmount" runat="server" Text="Total Amount"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("car_amount") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("car_amount") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtShipping" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="txtTotalAmount" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnCheckOut" runat="server" Text="Checkout>>" />
Reply
Answers (
2
)
Deleting multiple records by using checkbox
Delete Confirmation in gridview common command delete