c# - selected row in gridview -
i have 2 table in sql server follow
patientdetail - 1st table name patientid --- primary key firstname lastname patexam - 2nd table name pid ---- foreign key of first table patientid exam
i have 1 gridview in page shows column of first table below
<asp:gridview id="gvdoctorlist" runat="server" autogeneratecolumns="false" datasourceid="sqldatasource1" allowpaging="true" allowsorting="true" autogenerateeditbutton="true" autogeneratedeletebutton="true"> <columns> <asp:commandfield showselectbutton="true" /> <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], [patientdetails]"></asp:sqldatasource>
i have 1 button text value = "formatric3d" when select 1 row in gridview , click on button
value = "formatric3d",
so on click event want insert selected row patientid
button text value = "formatric3d"
table name patexam.
that means pid equal patientid
selected on gridview , exam equal button text value = "formatric3d"
.
is want?
<asp:button runat="server" id="btnexam" text="formatric3d" onclick="exam_clickhandler" /> <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" /> <asp:label runat="server" id="lblpid" visible="false" text='<%# eval("patientid") %>'></asp:label> </itemtemplate> </asp:templatefield> <asp:commandfield showselectbutton="true" /> <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> <h3>patient exams</h3> <asp:datalist runat="server" id="dtlexams"> <itemtemplate> <%#eval("exam") %> </itemtemplate> </asp:datalist> //////////////// tree view <asp:treeview runat="server" id="tvexams"> </asp:treeview>
on code behind page:
protected void exam_clickhandler(object sender, eventargs e) { foreach (gridviewrow row in gvdoctorlist.rows) { checkbox chk = (checkbox)row.findcontrol("chk"); if (chk.checked) { string patientid = ((label)row.findcontrol("lblpid")).text; string exam = ((button)sender).text; ///your insertion query goes here. /// getpatientexams(patientid); } } } protected void patient_examhandler(object sender, commandeventargs e) { string patientid = e.commandargument.tostring(); getpatientexams(patientid); } private void getpatientexams(string pid) { datatable exams = "get exam data db pid"; dtlexams.datasource = exams; dtlexams.databind();
//////////////// tree view treenode tnnn;
foreach (datarow row in exams.rows) { tnnn = new treenode(exams["prodshort"].tostring()); tvexams.nodes.add(tnnn); } }
Comments
Post a Comment