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

Manikavelu VelayuthamRank #413 · 6K reputationPosted Sep 26, 2010, 9:29 PM EDT
can you paste your code here, so that we can easily fix the bug in your code
faraz akram83 reputationPosted Sep 26, 2010, 9:52 PM EDT
<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 VelayuthamRank #413 · 6K reputationPosted Sep 26, 2010, 10:14 PM EDT
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 akram83 reputationPosted Sep 26, 2010, 10:19 PM EDT
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 VelayuthamRank #413 · 6K reputationPosted Sep 26, 2010, 10:27 PM EDT
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
}
karthick kumar106 reputationPosted Sep 26, 2010, 10:37 PM EDT
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.