Guest User

Untitled

a guest
Jul 17th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. int totalCount = grid.FindControl("employee_to_rep").Controls.Count;
  2. for (int i = 0; i < totalCount; i++)
  3. {
  4. CheckBox ck = (CheckBox)grid.FindControl("employee_to_rep").Controls[i];
  5. HiddenField employeeIDValue = (HiddenField)grid.FindControl("employeeidToRep").Controls[i];
  6. if (ck.Checked)
  7. {
  8. test = employeeIDValue.Value.ToString();
  9. }
  10. }
  11.  
  12. Object reference not set to an instance of an object.
  13. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  14.  
  15. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  16.  
  17. Source Error:
  18.  
  19. Line 80:
  20. Line 81: int totalCount = grid.FindControl("employee_to_rep").Controls.Count;
  21.  
  22. <tr>
  23. <th class="graytext r">Add Reps to Team:</th>
  24. <td>
  25. <asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID"
  26. DataSourceID="dsEmployees" AllowPaging="true" PageSize="1000" EnableViewState="false"
  27. GridLines="None" CssClass="clGridDirectory">
  28. <Columns>
  29. <asp:TemplateField >
  30. <ItemTemplate>
  31. <asp:CheckBox runat="server" ID='employee_to_rep' Text='<%# Eval("fullname") %>'/>
  32. <asp:HiddenField runat="server" ID="employeeidToRep" Value='<%# Eval("employeeid") %>'/>
  33. <asp:TextBox runat='server' ID='repID' Text='<%# Eval("rep_id") %>'/>
  34. </ItemTemplate>
  35. </asp:TemplateField>
  36. </Columns>
  37. </asp:GridView>
  38. <asp:SqlDataSource ID="dsEmployees" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
  39. SelectCommand="app_staff_without_team_select" SelectCommandType="StoredProcedure">
  40. </asp:SqlDataSource>
  41. </td>
  42. </tr>
  43.  
  44. grid.Row[0].FindControl("employee_to_rep")
  45.  
  46. grid.Row[grid.SelectedIndex].FindControl("employee_to_rep")
  47.  
  48. foreach (GridViewRow gvr in grid.Rows)
  49. {
  50. CheckBox ck = (CheckBox)gvr.FindControl("employee_to_rep");
  51. HiddenField employeeIDValue = (HiddenField)gvr.FindControl("employeeidToRep");
  52. if (ck.Checked)
  53. {
  54. test = employeeIDValue.Value.ToString();
  55. }
  56. }
  57.  
  58. int totalCount = grid.FindControl("employee_to_rep").Controls.Count;
  59.  
  60. var control = (CheckBox) grid.FindControl("employee_to_rep");
  61.  
  62. if (grid.FindControl("employee_to_rep") != null)
  63.  
  64. foreach (GridViewRow gvr in GridView1.Rows)
  65. {
  66. if (gvr.RowType == DataControlRowType.DataRow)
  67. {
  68. // do your thing
  69. }
  70. }
Add Comment
Please, Sign In to add comment