hi
i have a panel having grid view with only tow columns one is CHECKBOX and other is id, need to show data on right side of the grid of the specific row on selecting the check box C#
i have populated the datagrid and added a templeta control as check box i have also fired this event on checkbox changed
GridView1_SelectedIndexChanged1
one it comes to get the value of specifis cell throwing me exception "object refrence not set at the instance of..... use the new key word"
any fruitfull suggestions
thanks in advance
Loading
karthick kumarPosted Sep 27, 2010, 2:37 AM
First of all check whether the row is selected or not .you mentioned that u have only two columns one is CHECKBOX and other is id. when u try to get the Cells[3] value u may get this exception.provide exact cell value.
Manikavelu VelayuthamPosted Sep 27, 2010, 2:27 AM
Find the check box control in each row and check for the checked value, if its true, then find the nth columns value...
CheckBox chkName = (CheckBox )GridView1.Rows[count].FindControl("chkName");
if (chkName.Checked == true)
{
// do your code here
}
faraz akramPosted Sep 27, 2010, 2:19 AM
My question is that how i would b able to select a datagrid row through an item template check box in order to get the columns values.
thanks in adv
Manikavelu VelayuthamPosted Sep 27, 2010, 2:14 AM
1. There is no selectedrow in the grid, so you just need to check selectedrow not equals to null there
2. There is no Cells[3] in that selectedrow. before using the cells[3], you need to check not equals to null.
To solve this issue, put a debugger in that line and add a quick watch to see the exact output.
faraz akramPosted Sep 27, 2010, 1:52 AM
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="True"
oncheckedchanged="chkSelect_CheckedChanged" />
ItemTemplate>
<HeaderTemplate>
HeaderTemplate>
asp:TemplateField>
and this is code behind for check box check changed
GridViewRow row = GridView1.SelectedRow;
string s = GridView1.SelectedRow.Cells[3].Text; ----> here comes the exception
Manikavelu VelayuthamPosted Sep 27, 2010, 1:29 AM
can you paste your code here, so that we can easily fix the bug in your code