2013-08-21 20 views
1
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> 

<script type="text/javascript" language="javascript"> 

    function divexpandcollapse(divname) { 
     var div = document.getElementById(divname); 
     var img = document.getElementById('img' + divname); 
     if (div.style.display == "none") { 
      div.style.display = "inline"; 
      img.src = "../kjl_images/closed.gif"; 
     } else { 
      div.style.display = "none"; 
      img.src = "../kjl_images/open.gif"; 
     } 
    } 
</script> 

內蒙古電網不是在嵌套的GridView

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" 
runat="Server"> 
<div> 
<asp:GridView ID="gvParentGrid" runat="server" DataKeyNames="hatchid" 
Width="300"AutoGenerateColumns="false" 
OnRowDataBound="gvUserInfo_RowDataBound" GridLines="None" 
BorderStyle="Solid" BorderWidth="1px" BorderColor="#df5015">   
<Columns> 
<asp:TemplateField ItemStyle-Width="20px"> 
<ItemTemplate> 
<a href="JavaScript:divexpandcollapse('div<%# Eval("hatchid") %>');"> 
<img id="imgdiv<%# Eval("hatchid") %>" width="9px" border="0" 
src="../kjl_images/closed.gif" alt="" /> 
</a> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:BoundField DataField="hatchid" HeaderText="Hatch ID" /> 
<asp:BoundField DataField="hatcheryname" HeaderText="Hatchery Name" />     
    <asp:TemplateField> 
    <ItemTemplate> 
     <tr> 
     <td colspan="100%"> 
<div id="div<%# Eval("hatchid") %>" style="display: none; 
position: relative; left: 15px; overflow: auto"> 
asp:GridView ID="gvChildGrid" runat="server" 
AutoGenerateColumns="false" BorderStyle="Double" 
BorderColor="#df5015" GridLines="None" Width="250px">           
<Columns> 
<asp:BoundField DataField="hatchid" HeaderText="Region"/>            
<asp:BoundField DataField="name" HeaderText="Name"/> 
    </Columns> 
    </asp:GridView> 
     </div> 
      </td> 
       </tr> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
    </asp:GridView> 
</div> 

這裏.CS碼

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 
     FillHatcheryGridDetails(); 

    } 

} 

public void FillHatcheryGridDetails() 
{ 
    DataTable dthatcherygrid = new DataTable(); 
    dthatcherygrid = objhatcheryBAL.GetChickGridsdet(); 
    gvParentGrid.DataSource = dthatcherygrid; 
    gvParentGrid.DataBind(); 
} 

protected void gvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     GridView GridView2 = (GridView)e.Row.FindControl("gvChildGrid"); 
     int hatchid = Convert.ToInt16(e.Row.Cells[1].Text); 
     DataTable dtRegions = new DataTable(); 
     objhatcheryPL.hatchid = hatchid; 
     dtRegions = objhatcheryBAL.GetHatchidDetaisl(objhatcheryPL); 
     GridView2.DataSource = dtRegions; 
     GridView2.DataBind(); 
    } 
} 

我想盡一點我在谷歌搜索代碼IAM張貼是從顯示數據谷歌 。 我的問題是當我點擊菜單按鈕時,內部網格顯示空白。 (即使我的代碼也可以)。任何人都可以說我哪裏錯了。

+0

做標題顯示在內部網從div.style.display = "inline";更改爲div.style.display = "inline-table"; ? –

+0

@KarlAnderson不,但數據來到數據源 – Bhagavan

+2

嘗試將'div.style.display'從'inline'更改爲'block',然後顯示出來嗎? –

回答

2

changed div.style.display =「inline」; div.style.display =「block」;

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> 

<script type="text/javascript" language="javascript"> 

function divexpandcollapse(divname) { 
    var div = document.getElementById(divname); 
    var img = document.getElementById('img' + divname); 
    if (div.style.display == "none") { 
     div.style.display = "block"; 
     img.src = "../kjl_images/closed.gif"; 
    } else { 
     div.style.display = "none"; 
     img.src = "../kjl_images/open.gif"; 
    } 
} 
</script> 
0

我不得不因爲DIV沒有保持寬度值與divexpandcollapse功能