本文介绍了ASP.NET中的嵌套网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨....
我想创建一个父母&子网格视图....在父网格视图中,要显示依赖于主要人员的人员的姓名和总数...并且在子网格视图中要显示依赖人员的详细信息...任何人都可以帮助我...
我的尝试:
ASP.Net
Hi....
I want to create a parent & child grid view.... In parent grid view, want to display name and total number of the person dependent on the primary person.. and In child grid view want to display the details of the dependent person...can anyone help me...
What I have tried:
ASP.Net
</div>
<asp:GridView ID="Gv_RemodelPrimary" runat="server" AutoGenerateColumns="false" DataKeyNames="UHIDNO" Width="100%"
ShowFooter="true" class="table table-striped table-bordered table-hover"
OnRowDataBound="Gv_RemodelPrimary_OnRowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl_membername" runat="server" Text='<%#Eval("Membername") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl_membername" runat="server" Text='<%#Eval("No_of_depends") %>'></asp:Label>
<asp:GridView ID="Gv_RemodelDepen" runat="server" AutoGenerateColumns="false" Width="100%"
ShowFooter="true" class="table table-striped table-bordered table-hover">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl_dependentname" runat="server" Text='<%#Eval("Membername") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btn_markprimary" runat="server" Text="Mark Primary" />
</ItemTemplate></asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C#代码
C# code
protected void ClickView(object sender, EventArgs e)
{ using (SqlCommand cmd = con.CreateCommand())
{
con.Open();
SqlCommand com = new SqlCommand("SP_T_ReModelPrimary", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@UHIDNO", txtUHIDNo.Text);
SqlDataAdapter sda = new SqlDataAdapter(com);
DataSet ds = new DataSet();
sda.Fill(ds);
Gv_RemodelPrimary.DataSource = ds;
Gv_RemodelPrimary.DataBind();
con.Close();
}
}
protected void Gv_RemodelPrimary_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
con.Open();
GridView gv = (GridView)e.Row.FindControl("Gv_RemodelDepen");
//int CountryId = Convert.ToInt32(e.Row.Cells[1].Text);
SqlCommand cmd = new SqlCommand("SP_T_ReModelDependency", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UHIDNO", txtUHIDNo.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
gv.DataSource = ds;
gv.DataBind();
}
}
推荐答案
这篇关于ASP.NET中的嵌套网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!