我正在使用嵌套的GridViews,其中gridview中的每一行都具有子gridView。我正在使用父級GridView的RowDataBound事件綁定Child GridView。我的問題是,如何在父級gridViews RowDataBound事件中獲取Child GridView的Button findcontrol值。如何讓按鈕在嵌套網格中找到控件值使用c#
這是我的aspx
<asp:GridView ID="grdSubClaimOuter" SkinID="GridView" runat="server" Width="100%"
AutoGenerateColumns="false" OnRowDataBound="grdSubClaimOuter_RowDataBound" OnRowCommand="grdSubClaimOuter_RowCommand"
ShowFooter="false" AllowPaging="true" OnPageIndexChanging="grdSubClaimOuter_PageIndexChanging">
<%--<AlternatingRowStyle BackColor="ButtonFace" />--%>
<Columns>
<asp:TemplateField ItemStyle-Width="5%">
<ItemTemplate>
<asp:HiddenField ID="hdnClaimNo" runat="server" Value='<%# Eval("ClaimNo") %>' />
<asp:Image runat="server" ID="img1" ImageUrl="../images/Collapse_plus.png" />
</ItemTemplate>
<ItemStyle Width="5%"></ItemStyle>
</asp:TemplateField>
<asp:GridView ID="grdSubClaim" runat="server" SkinID="GridView" CellPadding="4" Width="100%"
AutoGenerateColumns="false" ShowFooter="false" OnRowEditing="grdSubClaim_RowEditing"
OnRowCommand="grdSubClaim_RowCommand" OnRowDeleting="grdSubClaim_RowDeleted"
AllowPaging="false" >
<%--SkinID="GridView"--%>
<Columns>
<asp:TemplateField FooterStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Sub Claim No
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblSubClaimNoValue" Width="" runat="server" Text='<%#Eval("SubClaimNo")%>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:Button ID="btnSubrogation" CssClass="groovybutton" runat="server" CommandName="Subrogation"
Text="Subrogation" CommandArgument='<%# Eval("ClaimNo") + "~" + Eval("SubClaimNo")%>' />
<asp:Button ID="btnSalvage" CssClass="groovybutton" runat="server" CommandName="Salvage"
Text="Salvage" CommandArgument='<%# Eval("ClaimNo") + "~" + Eval("SubClaimNo")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle CssClass="" />
<RowStyle CssClass="ob_gBody" />
<HeaderStyle CssClass="gridHeader" />
</asp:GridView>
<asp:Literal runat="server" ID="Literal2" Text="</td></tr>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
頁這是我的aspx.cs文件
protected void grdSubClaimOuter_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.ToString() != " ")
{
Literal ltrChild = (Literal)e.Row.FindControl("ltrChild");
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.Cells[0].FindControl("img1");
ltrChild.Text = ltrChild.Text.Replace("trChildGrid", "trChildGrid" + e.Row.RowIndex.ToString());
string strChildGrid = "trChildGrid" + e.Row.RowIndex.ToString();
e.Row.Cells[0].Attributes.Add("OnClick", "OpenTable('" + strChildGrid + "','" + img.ClientID + "')");
e.Row.Cells[0].RowSpan = 1;
System.Web.UI.WebControls.GridView gvChild = (System.Web.UI.WebControls.GridView)e.Row.FindControl("grdSubClaim");
PolicyProcessor.DAL.Claim.ClaimSubClaim objDALClaimSubClaim = new PolicyProcessor.DAL.Claim.ClaimSubClaim();
PolicyProcessor.BOL.Claim.ClaimSubClaim objInfoClaimSubClaim = new PolicyProcessor.BOL.Claim.ClaimSubClaim();
HiddenField hdnClaimNo = (HiddenField)e.Row.FindControl("hdnClaimNo");
if (hdnClaimNo.Value != "")
{
objInfoClaimSubClaim.ClaimNo = hdnClaimNo.Value;
}
else
{
objInfoClaimSubClaim.ClaimNo = "0";
}
DataSet dsChild;
dsChild = objDALClaimSubClaim.ResultSet(objInfoClaimSubClaim, "SelectInnerGrid");
if (dsChild.Tables[0].Rows.Count > 0)
{
Button btn = (Button)gvChild.FindControl("btnSalvage");
//btn is null how to get text value in btn
btn.ForeColor = System.Drawing.Color.Red;
gvChild.DataSource = dsChild;
gvChild.DataBind();
}
else
{
Helper.EmptyGrid(gvChild, dsChild.Tables[0]);
}
}
}
}
,如果有人知道,請幫我解決這個problem.thanks提前。
問題不清楚?因爲父網格將具有n個位於網格內的基於子按鈕。你能進一步解釋一下嗎? – Nikshep