There are values for each label, and even after i click on edit the fields get bound with the same data, so the data is there within readonly mode, and edit mode.. but still get that error..
Intermediate ASP.net User, Using VS2008/VS2010 with C# and SQL2005, SQL2008, Silverlight 3
---------------------
Mark as Answered if it helped
I think the issue is that you're doing findcontrol on the gridview, when you're supposed to do it on a specific gridviewrow. That's why it's always best to check for nulls prior to using any call to findcontrol.
Where exactly are you trying to use these findcontrol calls? For instance, if it's in say RowDataBound, you would use e.Row.FindControl(blahblah).
cubangt
Contributor
3052 Points
2402 Posts
What am i doing wrong?
Sep 04, 2009 09:40 PM|LINK
What is wrong with this:
Label
lblcost = (Label)gv_sku_details.FindControl("lblCost");
TextBox txtcost = (TextBox)gv_sku_details.FindControl("txtCost");
decimal lcost = decimal.Parse(lblcost.Text);
decimal dcost = decimal.Parse(txtcost.Text);
///////////////////////////////////////
I get this error when i call my method
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Line 142: decimal lcost = decimal.Parse(lblcost.Text);
Line 143: decimal dcost = decimal.Parse(txtcost.Text);
And here is my ASPX code:
<asp:TemplateField HeaderText="COST">
<ItemTemplate>
<asp:Label ID="lblCost" runat="server" Text='<%# Bind("tot_cost") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblCost" runat="server" Text='<%# Bind("tot_cost") %>' Visible="false"></asp:Label>
<asp:TextBox ID="txtCost" runat="server" Text='<%# Bind("tot_cost") %>' CssClass="BorderedTextBox" Width="80"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
---------------------
Mark as Answered if it helped
SGWellens
All-Star
126031 Points
10310 Posts
Moderator
Re: What am i doing wrong?
Sep 04, 2009 10:00 PM|LINK
What error?
Is FindControl not finding the control and returning 'Nothing'?
What is the value of lblcost.Text?
My blog
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: What am i doing wrong?
Sep 04, 2009 10:00 PM|LINK
What is the error exactly? I don't see it in your post (?).
cubangt
Contributor
3052 Points
2402 Posts
Re: What am i doing wrong?
Sep 04, 2009 10:07 PM|LINK
Man im so out of it today... sorry.. i edited the original post to include the error message..
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
---------------------
Mark as Answered if it helped
cubangt
Contributor
3052 Points
2402 Posts
Re: What am i doing wrong?
Sep 04, 2009 10:08 PM|LINK
There are values for each label, and even after i click on edit the fields get bound with the same data, so the data is there within readonly mode, and edit mode.. but still get that error..
---------------------
Mark as Answered if it helped
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: What am i doing wrong?
Sep 04, 2009 11:01 PM|LINK
I think the issue is that you're doing findcontrol on the gridview, when you're supposed to do it on a specific gridviewrow. That's why it's always best to check for nulls prior to using any call to findcontrol.
Where exactly are you trying to use these findcontrol calls? For instance, if it's in say RowDataBound, you would use e.Row.FindControl(blahblah).