Hi,
I am developing asp.net using c#.To display employee information in gridview control and to add checkbox within gridcontrol.i select checkbox the employee information to stored another table.my probloem the following error
Error: NullReference Exception was Unhandled by user code.
krishnaraj_c...
Member
63 Points
154 Posts
Grid View Check Box in asp.net
Feb 23, 2012 06:34 AM|LINK
Hi,
I am developing asp.net using c#.To display employee information in gridview control and to add checkbox within gridcontrol.i select checkbox the employee information to stored another table.my probloem the following error
Error: NullReference Exception was Unhandled by user code.
Error Line:String[] Values = tot.ToString().Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
code:
protected void BtnMove_Click(object sender, EventArgs e)
{
for (int r = 0; r < GridInpatient.Rows.Count; r++)
{
CheckBox chk1 = (CheckBox)GridInpatient.Rows[r].FindControl("myCheckBox");
if (chk1.Checked == true)
{
count = count + 1;
cellSelect = GridInpatient.Rows[r].Cells[1].Text;
tot += cellSelect + ",";
}
}
String[] Values = tot.ToString().Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
patient objVar = new patient();
objVar.MoveInbox(count, Values);
}
Source Code:
<asp:Panel ID="Panel3" runat="server"
style="top: 346px; left: 156px; position: absolute; height: 269px; width: 820px">
<asp:Button ID="BtnMove" runat="server" onclick="BtnMove_Click"
style="top: 231px; left: 396px; position: absolute; height: 26px; width: 56px; border-style: Solid"
Text="Submit" />
<asp:GridView ID="GridInpatient" runat="server" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
GridLines="Horizontal" PageSize="5" onpageindexchanging="GridInpatient_PageIndexChanging"
style="top: -2px; left: 2px; position: absolute; width: 813px; height: 220px;"
AllowPaging="True" ForeColor="Black">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox ID="myCheckBox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>
</asp:Panel>
Mahesh Darku...
Participant
896 Points
238 Posts
Re: Grid View Check Box in asp.net
Feb 23, 2012 06:47 AM|LINK
CheckBox chk1 = (CheckBox)GridInpatient.Rows[r].FindControl("myCheckBox");
check the name of the checkbox in grid i.e. id of that is macth with the ubove name....ie. with myCheckBox..
lakhi_moni3
Member
34 Points
12 Posts
Re: Grid View Check Box in asp.net
Feb 23, 2012 08:59 PM|LINK
Hi
Please check the variable "tot" for null/string.empty before performing the split function, if its not empty/null then perform the Split.
if(tot !=null && tot != String.Empty)
{
Values = tot.ToString().Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
wish this is helpful