Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int totalCount = grid.FindControl("employee_to_rep").Controls.Count;
- for (int i = 0; i < totalCount; i++)
- {
- CheckBox ck = (CheckBox)grid.FindControl("employee_to_rep").Controls[i];
- HiddenField employeeIDValue = (HiddenField)grid.FindControl("employeeidToRep").Controls[i];
- if (ck.Checked)
- {
- test = employeeIDValue.Value.ToString();
- }
- }
- Object reference not set to an instance of an object.
- 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.
- Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
- Source Error:
- Line 80:
- Line 81: int totalCount = grid.FindControl("employee_to_rep").Controls.Count;
- <tr>
- <th class="graytext r">Add Reps to Team:</th>
- <td>
- <asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID"
- DataSourceID="dsEmployees" AllowPaging="true" PageSize="1000" EnableViewState="false"
- GridLines="None" CssClass="clGridDirectory">
- <Columns>
- <asp:TemplateField >
- <ItemTemplate>
- <asp:CheckBox runat="server" ID='employee_to_rep' Text='<%# Eval("fullname") %>'/>
- <asp:HiddenField runat="server" ID="employeeidToRep" Value='<%# Eval("employeeid") %>'/>
- <asp:TextBox runat='server' ID='repID' Text='<%# Eval("rep_id") %>'/>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- </asp:GridView>
- <asp:SqlDataSource ID="dsEmployees" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
- SelectCommand="app_staff_without_team_select" SelectCommandType="StoredProcedure">
- </asp:SqlDataSource>
- </td>
- </tr>
- grid.Row[0].FindControl("employee_to_rep")
- grid.Row[grid.SelectedIndex].FindControl("employee_to_rep")
- foreach (GridViewRow gvr in grid.Rows)
- {
- CheckBox ck = (CheckBox)gvr.FindControl("employee_to_rep");
- HiddenField employeeIDValue = (HiddenField)gvr.FindControl("employeeidToRep");
- if (ck.Checked)
- {
- test = employeeIDValue.Value.ToString();
- }
- }
- int totalCount = grid.FindControl("employee_to_rep").Controls.Count;
- var control = (CheckBox) grid.FindControl("employee_to_rep");
- if (grid.FindControl("employee_to_rep") != null)
- foreach (GridViewRow gvr in GridView1.Rows)
- {
- if (gvr.RowType == DataControlRowType.DataRow)
- {
- // do your thing
- }
- }
Add Comment
Please, Sign In to add comment