I want have the gridview on one page as below
<asp:GridView ID="gvDoctorList" runat="server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
AllowPaging="True"
AllowSorting="True"
AutoGenerateEditButton="true"
AutoGenerateDeleteButton="true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server"
ID="chk"
OnCheckedChanged="chk_CheckedChanged"
AutoPostBack="true"/>
<asp:Label runat="server" ID="lblPID" Visible="false" Text='<%# Eval("PatientId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PatientId"
HeaderText="PatientId"
SortExpression="PatientId" />
<asp:BoundField DataField="firstname"
HeaderText="firstname"
SortExpression="firstname" />
<asp:BoundField DataField="lastname"
HeaderText="lastname"
SortExpression="lastname" />
<asp:BoundField DataField="sex"
HeaderText="sex"
SortExpression="sex" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyDatabaseConnectionString %>"
SelectCommand="SELECT [PatientId],[firstname], [lastname], [sex] FROM [PatientDetails]">
</asp:SqlDataSource>
Now I put the session on the checkbox change event as below
protected void chk_CheckedChanged(object sender, EventArgs e)
{
GridViewRow row = ((GridViewRow)((Control)sender).Parent.Parent);
string requestid = gvDoctorList.DataKeys[row.RowIndex].Value.ToString();
string cellvalue = row.Cells[1].Text;
Session["pId"] = cellvalue;
}
on the another page i want to get the value of session so i did something on another page as below
protected void Page_Load(object sender, EventArgs e)
{
if (Session["pId"] != null)
{
lblsession.Text = Session["pId"].ToString();
}
else
{
}
}
But the problem is that when i debug the code on checkbox change event particularly on session line it show me error that Object reference not set to an instance of an object.
I don't understand what wrong?
What i want to do is that take the value of patientid from gridview for which the user has check on checkbox....send the selected value to another page and want to insert the patientid into the sql table.
Please supply any example with coding or another good ideas.