944,103 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 2969
  • ASP.NET RSS
Nov 5th, 2009
0

Retrieve EditItemTemplate controls of GridView at code-behind file

Expand Post »
Hi,

I'm trying to access the RangeValidator control at my code-behind file. I keep on getting "Object reference not set to an instance of an object." exception. Can someone enlighten me?

ASPX:
ASP.NET Syntax (Toggle Plain Text)
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="subject_id" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="5" ForeColor="Black" GridLines="Horizontal" OnDataBound="GridView1_DataBound">
  2. <Columns>
  3.  
  4. <asp:TemplateField HeaderText="Hurdle Weight" SortExpression="hurdle_weight">
  5. <ItemTemplate>
  6. <asp:Label ID="Label113" runat="server" Text='<%# Bind("hurdle_weight") %>'></asp:Label>
  7. </ItemTemplate>
  8. <ItemStyle Wrap="false" />
  9. <EditItemTemplate>
  10. <asp:TextBox ID="textbox_hurdleWeight1" Width="30px" runat="server" Text='<%# Bind("hurdle_weight") %>' /> %
  11.  
  12. <asp:RangeValidator ID="RangeValidator16" runat="server" ControlToValidate="textbox_hurdleWeight1"
  13. Font-Names="Verdana"
  14. ErrorMessage="The hurdle weight must be less or equals with the available weight"
  15. Display="Static">*
  16. </asp:RangeValidator>
  17. </EditItemTemplate>
  18. </asp:TemplateField>

Code behind:
ASP.NET Syntax (Toggle Plain Text)
  1. protected void GridView1_Editing(object sender, GridViewEditEventArgs e)
  2. {
  3. string subjectID = dropdown_subjectCode.SelectedValue.ToString();
  4. int index = Convert.ToInt32(e.NewEditIndex);
  5.  
  6. RangeValidator validator = (RangeValidator)GridView1.Rows[index].NamingContainer.FindControl("RangeValidator16");
  7. validator.MaximumValue = db.getHurdleWeightBalance(subjectID);
  8. }
Last edited by dfs3000my; Nov 5th, 2009 at 12:23 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dfs3000my is offline Offline
21 posts
since Dec 2008
Nov 5th, 2009
0
Re: Retrieve EditItemTemplate controls of GridView at code-behind file
I have found the workaround for this. More details from here.

ASP.NET Syntax (Toggle Plain Text)
  1. protected void GridViewRowEventHandler(Object sender, GridViewRowEventArgs e)
  2. {
  3. string subjectID = dropdown_subjectCode.SelectedValue.ToString();
  4.  
  5. if (e.Row.RowState == DataControlRowState.Edit)
  6. {
  7. RangeValidator validator = (RangeValidator)e.Row.FindControl("RangeValidator16");
  8. validator.MaximumValue = db.getHurdleWeightBalance(subjectID);
  9. }
  10. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dfs3000my is offline Offline
21 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: web browser's Browser_DocumentCompleted event is firing only first time,plz help
Next Thread in ASP.NET Forum Timeline: help with datagrid





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC