我们怎样才能做到这一点?一旦页面加载,默认情况下会消耗childgridview [英] How we can achieve this? expending childgridview by default once page load over
本文介绍了我们怎样才能做到这一点?一旦页面加载,默认情况下会消耗childgridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是nestred gridview。显示父网格视图记录..如果任何行具有子网格视图的记录。我正在使用expand和collopase按钮显示。
一切正常。但是当你展开(+符号图像)时,这是有效的。它显示子gridview和当collopase( - 符号图像)时,子gridview隐藏。
aspx.cs
protected void Page_Load(object sender,EventArgs e)
{
if(!Page.IsPostBack)
{
using(SqlConnection con) = new SqlConnection(sqlconn))
{
con.Open();
string sqlqry =从父视图中选择figno,name,childflag;
SqlCommand cmd = new SqlCommand(sqlqry,con);
SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adap.Fill(dt);
C1GridView1.DataSource = dt;
C1GridView1.DataBind();
}
}
}
// onrowdatabound动作
protected void childgridbound(object sender,GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
Label lblflag =(Label)e.Row.FindControl(lblchild);
if(lblflag ==Y)
{
using(SqlConnection con = new SqlConnection(sqlconn))
{
con.Open();
string sqlqry =select id,child from childgrid;
SqlCommand cmd = new SqlCommand(sqlqry,con);
SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adap.Fill(dt);
GridView gvSub = e.Row.FindControl(gvsubstitue)as GridView;
gvSub.DataSource = dt;
gvSub.DataBind();
}
}
else {
}
}
}
aspx:
// javascript:
< script 类型 = text / javascript src = http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js > < / script >
< script 类型 = < span class =code-keyword> text / javascript >
$([src * = plus] ).live(click,function(){
$(this).closest(tr)。after(< tr > < td > < / td > < td colspan =' 999' > + $(这个).next()。html()+< / td > < / tr > )
$(this).attr(src,.. / image / Items / minus.png);
});
$([src * = minus])。live(click,function(){
$(this).attr(src,.. / image /Parts/plus.png);
$(this).closest(tr)。next()。remove();
});
< / script >
< asp:GridView ID = C1GridView1 宽度 = < span class =code-keyword> 1138px runat = server ShowFooter = true OnRowDataBound = childgrid_bound AutoGenerateColumns = false >
< 列 >
< asp:TemplateField HeaderText = 图# >
< ItemTemplate > ;
<! - subgridview for部分存在的子项 - >
< img id = imgpartsub runat = server alt = style = cursor:pointer src = ../ Image / Parts / plus.png / >
< < span class =code-leadattribute> asp:Panel ID = pnlOrders runat = server 样式 = display:none >
< asp:GridView ID = gvsubstitue runat = server AutoGenerateColumns = false >
< 列 >
< span class =code-keyword>< asp:TemplateField HeaderText = Id >
< ItemTemplate >
< asp:Label ID = lblidsub runat = server 文本 =' <% #Eval( id)%> ' 字体名称 = Sans-Serif < span class =code-attribute> 字体大小 = 12px > < / asp:Label >
< / ItemTemplate > < ItemStyle 宽度 = 130px / >
< / asp:TemplateField >
< asp:TemplateField HeaderText = 描述 >
< ItemTemplate < span class =code-keyword>>
< asp:Label ID = lbldessub runat = 服务器 文本 =' <% #Eval( descript)%> ' < span class =code-attribute>字体名称 = Sans-Serif 字体大小 = 12px > < / asp:Label >
< / ItemTemplate > < ItemStyle 宽度 = 130px / >
< ; / asp:TemplateField >
< /列 >
< / asp:GridView >
< / asp:Panel < span class =code-keyword>>
< asp :标签 ID = lblmfgsub runat = server 文字 =' <% #Eval( figno)%> ' 字体名称 = Sans-Serif 字体大小 = 12px > < / asp:标签 >
< / ItemTemplate >
< < span class =code-leadattribute> / asp:TemplateField >
< asp:TemplateField HeaderText = 姓名 >
< ItemTemplate >
< asp:标签 ID = lblpartname 宽度 = 278px < span class =code-attribute> runat = server 字体大小 = 12px 字体名称 = < span class =code-keyword> Sans-Serif 文本 =' <% #Eval( 名称)%> ' > < / asp:标签 >
< / ItemTemplate >
< asp:TemplateField HeaderText = ChildFLAG >
< ItemTemplate >
< asp:标签 ID = lblchild 宽度 = 278px runat = server 字体大小 = 12px 字体名称 = Sans-Serif 文本 =' <% #Eval( childflag)%> ' > < / asp:标签 >
< / ItemTemplate >
< / asp:TemplateField >
< / Columns >
< / asp: GridView >
单击+和 - (展开/折叠)时,此工作正常。
就我而言。一旦页面加载,如果任何父gridview有子gridview,它应该自动expaned( - 符号)
那么asusual +和 - click(collopse和expand))应该工作。
谢谢。
解决方案
([src * = plus])。live(click ,function(){
(this).closest(tr)。after(< tr > < td > < / td > < td colspan =' 999' > +
(this).next()。html()+< / td > < / tr > 跨度>)
I am using nestred gridview. showing parent gridview records.. if any of row has records of child gridview. i am showing using expand and collopase button.
this works fine. But this works when you expand on (+ symbol image). it shows child gridview and when collopase(- symbol image), child gridview hides.
aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
using (SqlConnection con = new SqlConnection(sqlconn))
{
con.Open();
string sqlqry = "select figno,name,childflag from parentview";
SqlCommand cmd = new SqlCommand(sqlqry,con);
SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adap.Fill(dt);
C1GridView1.DataSource = dt;
C1GridView1.DataBind();
}
}
}
// onrowdatabound action
protected void childgridbound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblflag = (Label)e.Row.FindControl("lblchild");
if(lblflag=="Y")
{
using (SqlConnection con = new SqlConnection(sqlconn))
{
con.Open();
string sqlqry = "select id, descript from childgrid";
SqlCommand cmd = new SqlCommand(sqlqry,con);
SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adap.Fill(dt);
GridView gvSub = e.Row.FindControl("gvsubstitue") as GridView;
gvSub.DataSource = dt;
gvSub.DataBind();
}
}
else{
}
}
}
aspx:
//javascript:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("[src*=plus]").live("click", function () {
$(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
$(this).attr("src", "../image/Parts/minus.png");
});
$("[src*=minus]").live("click", function () {
$(this).attr("src", "../image/Parts/plus.png");
$(this).closest("tr").next().remove();
});
</script>
<asp:GridView ID="C1GridView1" Width="1138px" runat="server" ShowFooter="true" OnRowDataBound="childgrid_bound" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="FIG#">
<ItemTemplate>
<!-- subgridview for sub items if exists for part-->
<img id="imgpartsub" runat="server" alt = "" style="cursor: pointer" src="../Image/Parts/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvsubstitue" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderText="Id">
<ItemTemplate>
<asp:Label ID="lblidsub" runat="server" Text='<%# Eval("id") %>' Font-Names="Sans-Serif" Font-Size="12px"></asp:Label>
</ItemTemplate><ItemStyle Width="130px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Descript">
<ItemTemplate>
<asp:Label ID="lbldessub" runat="server" Text='<%# Eval("descript") %>' Font-Names="Sans-Serif" Font-Size="12px"></asp:Label>
</ItemTemplate><ItemStyle Width="130px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
<asp:Label ID="lblmfgsub" runat="server" Text='<%# Eval("figno") %>' Font-Names="Sans-Serif" Font-Size="12px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NAME">
<ItemTemplate>
<asp:Label ID="lblpartname" Width="278px" runat="server" Font-Size="12px" Font-Names="Sans-Serif" Text='<%# Eval("name") %>' ></asp:Label>
</ItemTemplate>
<asp:TemplateField HeaderText="ChildFLAG">
<ItemTemplate>
<asp:Label ID="lblchild" Width="278px" runat="server" Font-Size="12px" Font-Names="Sans-Serif" Text='<%# Eval("childflag") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This works fine when you click on + and - (expand/collapse).
In my case. once page load over, if any parent gridview has child gridview, it should have expaned automatically(- symbol)
Then asusual + and - click (collopse and expand)) should work.
Thank you.
解决方案
("[src*=plus]").live("click", function () {
(this).closest("tr").after("<tr><td></td><td colspan = '999'>" +
(this).next().html() + "</td></tr>")
这篇关于我们怎样才能做到这一点?一旦页面加载,默认情况下会消耗childgridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文