本文介绍了如何在asp.net中的嵌套网格中获取DataKeyNames的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我创建了3个名为dgvBranch,dgvCourse和dgvSubject的GridView。 dgvCourse是dgvSubject的父级,dgvBranch是dgvCourse的父级。 点击dgvSubject的删除按钮我想要dgvBranch中Selected Branch的数据键,dgvCourse中选择的课程和dgvSubject中的选定主题。
Here I have created 3 GridViews named as dgvBranch, dgvCourse and dgvSubject. dgvCourse is parent of dgvSubject and dgvBranch is parent of dgvCourse. On click of "Delete" button of dgvSubject i want datakey of Selected Branch in dgvBranch , selected Course in dgvCourse and selected subject in dgvSubject.
<div class="table-responsive">
<asp:GridView ID="dgvBranch" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-striped"
DataKeyNames="BranchID" ShowHeader="false" OnRowDataBound="dgvBranch_RowDataBound">
<Columns>
<asp:BoundField DataField="BranchName" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:HiddenField ID="HFBranch" runat="server" Value='<%# Eval("BranchID") %>' />
<asp:LinkButton ID="lnbAddCourse" runat="server" CausesValidation="false" Text="Add Course"
OnClick="lnbAddCourse_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<img alt="" style="cursor: pointer" src="../img/down.jpg" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="dgvCourse" runat="server" AutoGenerateColumns="False" DataKeyNames="CourseID"
CssClass="table table-bordered table-striped" OnRowDataBound="dgvCourse_RowDataBound">
<Columns>
<asp:BoundField HeaderText="Course Name" DataField="Name" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lnbDelete" runat="server" CausesValidation="false" Text="Delete"
OnClick="lnbDeleteCourse_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:HiddenField ID="HFCourse" runat="server" Value='<%# Eval("CourseID") %>' />
<asp:LinkButton ID="lnbAddSubject" runat="server" CausesValidation="false" Text="Add Subject"
OnClick="lnbAddSubject_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<img alt="" style="cursor: pointer" src="../img/show.jpg" />
<asp:Panel ID="pnlSubject" runat="server" Style="display: none">
<asp:GridView ID="dgvSubject" runat="server" AutoGenerateColumns="False" DataKeyNames="SubjectID"
CssClass="table table-bordered table-striped" OnRowDataBound="dgvSubject_RowDataBound">
<Columns>
<asp:BoundField HeaderText="Subject Name" DataField="SubjectName" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lnbDeleteSubject" runat="server" CausesValidation="false" Text="Delete"
OnClick="lnbDeleteSubject_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
推荐答案
这篇关于如何在asp.net中的嵌套网格中获取DataKeyNames的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!