如何在GridView的TemplateField中找到Control?

发布于 2024-11-27 03:13:12 字数 27081 浏览 1 评论 0原文

如果我需要查找 GridView Template 内的任何 Control,更具体地说 FindControl 方法如何工作>项目模板?

我有一个超链接,但无法找到相同的内容。

用代码更新问题

GridView 代码如下:

<asp:GridView ID="grvYourOpportunities" runat="server" AllowPaging="True" AutoGenerateColumns="False"
        DataKeyNames="ID#,B,H" PageSize="20" CellPadding="4" ForeColor="#333333" GridLines="Both"
        OnRowDataBound="grvYourOpt_RowDataBound">
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
          <asp:TemplateField>
                <HeaderTemplate>
                    i
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("i") %>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField>
                <HeaderTemplate>
                    H
                </HeaderTemplate>
                <ItemTemplate>

                    <%--<a href="javascript:ShowChildGrid('div<%# Eval("ID#") %>');">
                    <img id="imgdiv<%# Eval("ID#") %>" alt="Click" border="0" src="plus.gif" runat="server" />  </a>  --%>

                    <asp:HyperLink runat="server" ID="hlPlus" ImageUrl="~/plus.gif"></asp:HyperLink>

                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    B
                </HeaderTemplate>
                <ItemTemplate>
                    <%--<%# Eval("B") %>--%>
                    <a href="javascript:ShowChildGridForBCol('div1<%# Eval("ID#") %>');">
                        <img id="imgdiv1<%# Eval("ID#") %>" alt="Click here" border="0" src="tempY.png" />
                    </a>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    ID.Nr.
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("ID#")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Entry Date
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Entry Date") %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderStyle-Width="20px" ItemStyle-Width="20px">
                <HeaderTemplate>
                    BU
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("BU")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    BE
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("BE")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Product Family
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Product Family")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Project Name
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Project Name")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    SOP
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("SOP")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Award Date
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Award Date")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Milestone Next Date
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Milestone Next Date")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Contract Status
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Contract Status")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Prob.Of Success
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("ProbSuccess")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Key Account
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Key Account")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Sales SubRegion
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Sales SubRegion")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Growth
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Growth")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Sales p.a.OE mio$
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("SalesOE")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Sales p.a.AM mio$
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("SalesAM")%>
                </ItemTemplate>
            </asp:TemplateField>
            <%--GridView 2, 3--%>
            <asp:TemplateField>
                <ItemTemplate>
                    <tr>
                        <td align="left" style="margin-left: 10px;" colspan="5">
                            <div id="div<%# Eval("ID#") %>" style="display: none; position: relative; left: 110px;">
                                <asp:GridView ID="GridView2" runat="server" Width="40%" AutoGenerateColumns="false"
                                    DataKeyNames="Entry Date" EmptyDataText="No orders for this customer." CellPadding="0"
                                    ForeColor="#333333" GridLines="Both">
                                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                    <HeaderStyle CssClass="header" />
                                    <RowStyle CssClass="row" />
                                    <Columns>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("ID#")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Entry Date") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("ID#")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField ItemStyle-Wrap="false">
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Other Text") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td align="left" colspan="19">
                            <div id="div1<%# Eval("ID#") %>" style="display: none; position:relative; left: 110px;">
                                <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="false" DataKeyNames="Entry Date"
                                    EmptyDataText="No orders for this customer." CellPadding="0" ForeColor="#333333"
                                    GridLines="Both" Width="100%">
                                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                    <%--<HeaderStyle CssClass="header" />
                                    <RowStyle CssClass="row" />--%>
                                    <Columns>

                                        <%--<asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                            </ItemTemplate>
                                        </asp:TemplateField>--%>

                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("ID#")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                       <%-- <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Entry Date") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderStyle-Width="20px" ItemStyle-Width="20px">
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("BU")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("BE")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Product Family")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Project Name")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("SOP")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Award Date")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Milestone Next Date")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Contract Status")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("ProbSuccess")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Key Account")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Sales SubRegion")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Growth")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("SalesOE")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("SalesAM")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>--%>
                                    </Columns>
                                </asp:GridView>
                            </div>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

GridViewRowDataBound事件如下;

Protected void grvYourOpt_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string colId = grvYourOpportunities.DataKeys[e.Row.RowIndex].Values[0].ToString();
        string colB = grvYourOpportunities.DataKeys[e.Row.RowIndex].Values[1].ToString();
        string colH = grvYourOpportunities.DataKeys[e.Row.RowIndex].Values[2].ToString();

        #region "Commented Code for Col.B"

        //if (colB == "Y")
        //{
        //    e.Row.Cells[2].Text = "<img src='tempY.png'>";

        //}
        //else
        //{
        //    e.Row.Cells[2].Text = "<img src='tempN.png'>";
        //}
        #endregion

        #region "Commented code for Col.H"

        if (colH == "1")
        {
            e.Row.Cells[1].Text = string.Empty;
            //e.Row.Cells[1].Text = "<a href=''> <img id='13' alt='Click' border='0' src='plus.gif'/> </a>";
            string js = string.Format("javascript:ShowChildGrid('div{0}');", colId);
            HyperLink lnk = (HyperLink)e.Row.FindControl("hlPlus");
            if (lnk!=null)
            {
                lnk.NavigateUrl = js;
                lnk.ImageUrl = "plus.gif";
                lnk.Visible = true;
            }
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "HCol", "ShowChildGrid("+ colId + ");", true);
        }
        else
        {
            e.Row.Cells[1].Text = string.Empty;
            e.Row.Cells[1].Text = "";
        }
        #endregion

        DataTable dt1 = new DataTable();
        DataTable dt2 = new DataTable();

        DataRow dr1 = null;
        DataRow dr2 = null;
        DataRow dr3 = null;
        DataRow dr4 = null;
        DataRow dr5 = null;
        DataRow dr7 = null;

        DataRow r = dt1.NewRow();

        DataSet ds1 = new DataSet();
        DataSet ds2 = new DataSet();

        dt1.TableName = "Opportunity1";

        dt1.Columns.Add(new System.Data.DataColumn("ID#", typeof(System.String)));
        dt1.Columns.Add(new System.Data.DataColumn("Entry Date", typeof(System.String)));
        dt1.Columns.Add(new System.Data.DataColumn("Other Text", typeof(System.String)));
        ds1.Tables.Add(dt1);

        dt2.Columns.Add(new System.Data.DataColumn("ID#", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Entry Date", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("BU", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("BE", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Product Family", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Project Name", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("SOP", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Award Date", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Milestone Next Date", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Contract Status", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("ProbSuccess", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Key Account", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Sales SubRegion", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Growth", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("SalesOE", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("SalesAM", typeof(System.String)));
        ds2.Tables.Add(dt2);

        dr2 = dt1.NewRow();
        dr3 = dt1.NewRow();
        dr4 = dt1.NewRow();
        dr5 = dt1.NewRow();

        dr1["ID#"] = "";
        dr2["ID#"] = "";
        dr3["ID#"] = "";
        dr4["ID#"] = "";
        dr5["ID#"] = "";

        dr1["Entry Date"] = "18/01/2010";
        dr2["Entry Date"] = "19/01/2010";
        dr3["Entry Date"] = "20/01/2010";
        dr4["Entry Date"] = "21/01/2010";
        dr5["Entry Date"] = "14/01/2010";

        dr1["Other Text"] = "17:25CET changed by"; // - product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";
        dr2["Other Text"] = "18:44CET changed by"; //- product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";
        dr3["Other Text"] = "19:25CET changed by"; //- product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";
        dr4["Other Text"] = "14:25CET changed by"; //- product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";
        dr5["Other Text"] = "11:25CET changed by"; //- product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";

        dt1.Rows.Add(dr1);
        dt1.Rows.Add(dr2);
        dt1.Rows.Add(dr3);
        dt1.Rows.Add(dr4);
        dt1.Rows.Add(dr5);

        GridView gv12 = (GridView)e.Row.FindControl("GridView2");
        gv12.DataSource = ds1.Tables[0];
        gv12.DataBind();

        for (int i = 0; i < gv12.Rows.Count; i++)
        {
            gv12.RowStyle.BackColor = System.Drawing.Color.Gray;
        }


        dr7 = dt2.NewRow();

        dr7["ID#"] = "11-0101";
        dr7["Entry Date"] = "19/01/2010";
        dr7["BU"] = "VDC";
        dr7["BE"] = "ASES";
        dr7["Product Family"] = "Car Air Systems";
        dr7["Project Name"] = "Example";
        dr7["SOP"] = "09/08/2011";
        dr7["Award Date"] = "10/2011";
        dr7["Milestone Next Date"] = System.DateTime.Today.ToString("dd.MM.yyyy");
        dr7["Contract Status"] = "won";
        dr7["ProbSuccess"] = "70%";
        dr7["Key Account"] = "E-Paccar";
        dr7["Sales SubRegion"] = "North America";
        dr7["Growth"] = "10%";
        dr7["SalesOE"] = "150";
        dr7["SalesAM"] = "18";

        dt2.Rows.Add(dr7);

        GridView gv13 = (GridView)e.Row.FindControl("GridView3");
        gv13.DataSource = ds2.Tables[0];
        gv13.DataBind();
    }
}

hyperlink hlPlusGridView 模板字段(Item Template)内的一个hyperlink字段。

How does FindControl method works if I need to find any Control which is inside GridView Template, more specifically ItemTemplate?

I have a hyperlink but it is not able to find the same.

Question updated with code

GridView Code is below:

<asp:GridView ID="grvYourOpportunities" runat="server" AllowPaging="True" AutoGenerateColumns="False"
        DataKeyNames="ID#,B,H" PageSize="20" CellPadding="4" ForeColor="#333333" GridLines="Both"
        OnRowDataBound="grvYourOpt_RowDataBound">
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
          <asp:TemplateField>
                <HeaderTemplate>
                    i
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("i") %>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField>
                <HeaderTemplate>
                    H
                </HeaderTemplate>
                <ItemTemplate>

                    <%--<a href="javascript:ShowChildGrid('div<%# Eval("ID#") %>');">
                    <img id="imgdiv<%# Eval("ID#") %>" alt="Click" border="0" src="plus.gif" runat="server" />  </a>  --%>

                    <asp:HyperLink runat="server" ID="hlPlus" ImageUrl="~/plus.gif"></asp:HyperLink>

                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    B
                </HeaderTemplate>
                <ItemTemplate>
                    <%--<%# Eval("B") %>--%>
                    <a href="javascript:ShowChildGridForBCol('div1<%# Eval("ID#") %>');">
                        <img id="imgdiv1<%# Eval("ID#") %>" alt="Click here" border="0" src="tempY.png" />
                    </a>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    ID.Nr.
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("ID#")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Entry Date
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Entry Date") %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderStyle-Width="20px" ItemStyle-Width="20px">
                <HeaderTemplate>
                    BU
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("BU")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    BE
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("BE")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Product Family
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Product Family")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Project Name
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Project Name")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    SOP
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("SOP")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Award Date
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Award Date")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Milestone Next Date
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Milestone Next Date")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Contract Status
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Contract Status")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Prob.Of Success
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("ProbSuccess")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Key Account
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Key Account")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Sales SubRegion
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Sales SubRegion")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Growth
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("Growth")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Sales p.a.OE mio$
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("SalesOE")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Sales p.a.AM mio$
                </HeaderTemplate>
                <ItemTemplate>
                    <%# Eval("SalesAM")%>
                </ItemTemplate>
            </asp:TemplateField>
            <%--GridView 2, 3--%>
            <asp:TemplateField>
                <ItemTemplate>
                    <tr>
                        <td align="left" style="margin-left: 10px;" colspan="5">
                            <div id="div<%# Eval("ID#") %>" style="display: none; position: relative; left: 110px;">
                                <asp:GridView ID="GridView2" runat="server" Width="40%" AutoGenerateColumns="false"
                                    DataKeyNames="Entry Date" EmptyDataText="No orders for this customer." CellPadding="0"
                                    ForeColor="#333333" GridLines="Both">
                                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                    <HeaderStyle CssClass="header" />
                                    <RowStyle CssClass="row" />
                                    <Columns>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("ID#")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Entry Date") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("ID#")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField ItemStyle-Wrap="false">
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Other Text") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td align="left" colspan="19">
                            <div id="div1<%# Eval("ID#") %>" style="display: none; position:relative; left: 110px;">
                                <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="false" DataKeyNames="Entry Date"
                                    EmptyDataText="No orders for this customer." CellPadding="0" ForeColor="#333333"
                                    GridLines="Both" Width="100%">
                                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                    <%--<HeaderStyle CssClass="header" />
                                    <RowStyle CssClass="row" />--%>
                                    <Columns>

                                        <%--<asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                            </ItemTemplate>
                                        </asp:TemplateField>--%>

                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("ID#")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                       <%-- <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Entry Date") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderStyle-Width="20px" ItemStyle-Width="20px">
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("BU")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("BE")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Product Family")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Project Name")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("SOP")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Award Date")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Milestone Next Date")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Contract Status")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("ProbSuccess")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Key Account")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Sales SubRegion")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("Growth")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("SalesOE")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <%# Eval("SalesAM")%>
                                            </ItemTemplate>
                                        </asp:TemplateField>--%>
                                    </Columns>
                                </asp:GridView>
                            </div>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

The RowDataBound event of the parent GridView is as below;

Protected void grvYourOpt_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string colId = grvYourOpportunities.DataKeys[e.Row.RowIndex].Values[0].ToString();
        string colB = grvYourOpportunities.DataKeys[e.Row.RowIndex].Values[1].ToString();
        string colH = grvYourOpportunities.DataKeys[e.Row.RowIndex].Values[2].ToString();

        #region "Commented Code for Col.B"

        //if (colB == "Y")
        //{
        //    e.Row.Cells[2].Text = "<img src='tempY.png'>";

        //}
        //else
        //{
        //    e.Row.Cells[2].Text = "<img src='tempN.png'>";
        //}
        #endregion

        #region "Commented code for Col.H"

        if (colH == "1")
        {
            e.Row.Cells[1].Text = string.Empty;
            //e.Row.Cells[1].Text = "<a href=''> <img id='13' alt='Click' border='0' src='plus.gif'/> </a>";
            string js = string.Format("javascript:ShowChildGrid('div{0}');", colId);
            HyperLink lnk = (HyperLink)e.Row.FindControl("hlPlus");
            if (lnk!=null)
            {
                lnk.NavigateUrl = js;
                lnk.ImageUrl = "plus.gif";
                lnk.Visible = true;
            }
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "HCol", "ShowChildGrid("+ colId + ");", true);
        }
        else
        {
            e.Row.Cells[1].Text = string.Empty;
            e.Row.Cells[1].Text = "";
        }
        #endregion

        DataTable dt1 = new DataTable();
        DataTable dt2 = new DataTable();

        DataRow dr1 = null;
        DataRow dr2 = null;
        DataRow dr3 = null;
        DataRow dr4 = null;
        DataRow dr5 = null;
        DataRow dr7 = null;

        DataRow r = dt1.NewRow();

        DataSet ds1 = new DataSet();
        DataSet ds2 = new DataSet();

        dt1.TableName = "Opportunity1";

        dt1.Columns.Add(new System.Data.DataColumn("ID#", typeof(System.String)));
        dt1.Columns.Add(new System.Data.DataColumn("Entry Date", typeof(System.String)));
        dt1.Columns.Add(new System.Data.DataColumn("Other Text", typeof(System.String)));
        ds1.Tables.Add(dt1);

        dt2.Columns.Add(new System.Data.DataColumn("ID#", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Entry Date", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("BU", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("BE", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Product Family", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Project Name", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("SOP", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Award Date", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Milestone Next Date", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Contract Status", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("ProbSuccess", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Key Account", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Sales SubRegion", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("Growth", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("SalesOE", typeof(System.String)));
        dt2.Columns.Add(new System.Data.DataColumn("SalesAM", typeof(System.String)));
        ds2.Tables.Add(dt2);

        dr2 = dt1.NewRow();
        dr3 = dt1.NewRow();
        dr4 = dt1.NewRow();
        dr5 = dt1.NewRow();

        dr1["ID#"] = "";
        dr2["ID#"] = "";
        dr3["ID#"] = "";
        dr4["ID#"] = "";
        dr5["ID#"] = "";

        dr1["Entry Date"] = "18/01/2010";
        dr2["Entry Date"] = "19/01/2010";
        dr3["Entry Date"] = "20/01/2010";
        dr4["Entry Date"] = "21/01/2010";
        dr5["Entry Date"] = "14/01/2010";

        dr1["Other Text"] = "17:25CET changed by"; // - product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";
        dr2["Other Text"] = "18:44CET changed by"; //- product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";
        dr3["Other Text"] = "19:25CET changed by"; //- product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";
        dr4["Other Text"] = "14:25CET changed by"; //- product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";
        dr5["Other Text"] = "11:25CET changed by"; //- product family: ABS, Milestone Date: 23.02.1022, Contract Status: Signed, Probability of success: 100%";

        dt1.Rows.Add(dr1);
        dt1.Rows.Add(dr2);
        dt1.Rows.Add(dr3);
        dt1.Rows.Add(dr4);
        dt1.Rows.Add(dr5);

        GridView gv12 = (GridView)e.Row.FindControl("GridView2");
        gv12.DataSource = ds1.Tables[0];
        gv12.DataBind();

        for (int i = 0; i < gv12.Rows.Count; i++)
        {
            gv12.RowStyle.BackColor = System.Drawing.Color.Gray;
        }


        dr7 = dt2.NewRow();

        dr7["ID#"] = "11-0101";
        dr7["Entry Date"] = "19/01/2010";
        dr7["BU"] = "VDC";
        dr7["BE"] = "ASES";
        dr7["Product Family"] = "Car Air Systems";
        dr7["Project Name"] = "Example";
        dr7["SOP"] = "09/08/2011";
        dr7["Award Date"] = "10/2011";
        dr7["Milestone Next Date"] = System.DateTime.Today.ToString("dd.MM.yyyy");
        dr7["Contract Status"] = "won";
        dr7["ProbSuccess"] = "70%";
        dr7["Key Account"] = "E-Paccar";
        dr7["Sales SubRegion"] = "North America";
        dr7["Growth"] = "10%";
        dr7["SalesOE"] = "150";
        dr7["SalesAM"] = "18";

        dt2.Rows.Add(dr7);

        GridView gv13 = (GridView)e.Row.FindControl("GridView3");
        gv13.DataSource = ds2.Tables[0];
        gv13.DataBind();
    }
}

The hyperlink hlPlus is a hyperlink field inside GridView's Template Field(Item Template).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

貪欢 2024-12-04 03:13:12

试试这个:

foreach(GridViewRow row in GridView1.Rows) {
    if(row.RowType == DataControlRowType.DataRow) {
        HyperLink myHyperLink = row.FindControl("myHyperLinkID") as HyperLink;
    }
}

如果您正在处理 RowDataBound 事件,则如下所示:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink myHyperLink = e.Row.FindControl("myHyperLinkID") as HyperLink;
    }
}

Try this:

foreach(GridViewRow row in GridView1.Rows) {
    if(row.RowType == DataControlRowType.DataRow) {
        HyperLink myHyperLink = row.FindControl("myHyperLinkID") as HyperLink;
    }
}

If you are handling RowDataBound event, it's like this:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink myHyperLink = e.Row.FindControl("myHyperLinkID") as HyperLink;
    }
}
别挽留 2024-12-04 03:13:12

您可以使用此代码在 GridView 中查找 HyperLink。使用 e.Row.Cells[0].Controls[0] 查找 GridView 中控件的第一个位置。

protected void AspGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{    
  if(e.Row.RowType == DataControlRowType.DataRow)
    {
        DataRowView v = (DataRowView)e.Row.DataItem;           

        if (e.Row.Cells.Count > 0 && e.Row.Cells[0] != null && e.Row.Cells[0].Controls.Count > 0)
        {
            HyperLink link = e.Row.Cells[0].Controls[0] as HyperLink;
            if (link != null)
            {                    
                    link.Text = "Edit";
            }               
        }       

    }
}

You can use this code to find HyperLink in GridView. Use of e.Row.Cells[0].Controls[0] to find First position of control in GridView.

protected void AspGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{    
  if(e.Row.RowType == DataControlRowType.DataRow)
    {
        DataRowView v = (DataRowView)e.Row.DataItem;           

        if (e.Row.Cells.Count > 0 && e.Row.Cells[0] != null && e.Row.Cells[0].Controls.Count > 0)
        {
            HyperLink link = e.Row.Cells[0].Controls[0] as HyperLink;
            if (link != null)
            {                    
                    link.Text = "Edit";
            }               
        }       

    }
}
舂唻埖巳落 2024-12-04 03:13:12

我已经完成了访问单元格控件内的控件。在所有控件集合中查找。

 ControlCollection cc = (ControlCollection)e.Row.Controls[1].Controls;

 Label lbCod = (Label)cc[1];

I have done it accessing the controls inside the cell control. Find in all control collections.

 ControlCollection cc = (ControlCollection)e.Row.Controls[1].Controls;

 Label lbCod = (Label)cc[1];
空城缀染半城烟沙 2024-12-04 03:13:12

尝试使用下面的代码。

就像LinkBut​​ton、Label、HtmlAnchor 和HtmlInputControl 中的GridView 一样。

<asp:GridView ID="mainGrid" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-hover tablesorter"
    OnRowDataBound="mainGrid_RowDataBound"  EmptyDataText="No Data Found.">
    <Columns>
        <asp:TemplateField HeaderText="HeaderName" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
            <ItemTemplate>
                <asp:Label runat="server" ID="lblName" Text=' <%# Eval("LabelName") %>'></asp:Label>
                <asp:LinkButton ID="btnLink" runat="server">ButtonName</asp:LinkButton>
                <a href="javascript:void(0);" id="btnAnchor" runat="server">ButtonName</a>
                <input type="hidden" runat="server" id="hdnBtnInput" value='<%#Eval("ID") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

处理 RowDataBound 事件,

protected void mainGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Label lblName = (Label)e.Row.FindControl("lblName");
        LinkButton btnLink = (LinkButton)e.Row.FindControl("btnLink");
        HtmlAnchor btnAnchor = (HtmlAnchor)e.Row.FindControl("btnAnchor");
        HtmlInputControl hdnBtnInput = (HtmlInputControl)e.Row.FindControl("hdnBtnInput");
    }
}

Try with below code.

Like GridView in LinkButton, Label, HtmlAnchor and HtmlInputControl.

<asp:GridView ID="mainGrid" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-hover tablesorter"
    OnRowDataBound="mainGrid_RowDataBound"  EmptyDataText="No Data Found.">
    <Columns>
        <asp:TemplateField HeaderText="HeaderName" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
            <ItemTemplate>
                <asp:Label runat="server" ID="lblName" Text=' <%# Eval("LabelName") %>'></asp:Label>
                <asp:LinkButton ID="btnLink" runat="server">ButtonName</asp:LinkButton>
                <a href="javascript:void(0);" id="btnAnchor" runat="server">ButtonName</a>
                <input type="hidden" runat="server" id="hdnBtnInput" value='<%#Eval("ID") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Handling RowDataBound event,

protected void mainGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Label lblName = (Label)e.Row.FindControl("lblName");
        LinkButton btnLink = (LinkButton)e.Row.FindControl("btnLink");
        HtmlAnchor btnAnchor = (HtmlAnchor)e.Row.FindControl("btnAnchor");
        HtmlInputControl hdnBtnInput = (HtmlInputControl)e.Row.FindControl("hdnBtnInput");
    }
}
叶落知秋 2024-12-04 03:13:12
protected void gvTurnos_RowDataBound(object sender, GridViewRowEventArgs e)
{
    try
    {

        if (e.Row.RowType == DataControlRowType.EmptyDataRow)
        {
            LinkButton btn = (LinkButton)e.Row.FindControl("btnAgregarVacio");
            if (btn != null)
            {
                btn.Visible = rbFiltroEstatusCampus.SelectedValue == "1" ? true : false;
            }
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
protected void gvTurnos_RowDataBound(object sender, GridViewRowEventArgs e)
{
    try
    {

        if (e.Row.RowType == DataControlRowType.EmptyDataRow)
        {
            LinkButton btn = (LinkButton)e.Row.FindControl("btnAgregarVacio");
            if (btn != null)
            {
                btn.Visible = rbFiltroEstatusCampus.SelectedValue == "1" ? true : false;
            }
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
凶凌 2024-12-04 03:13:12

如果您的 GridView 是 databond,请在您检索的结果集中创建一个索引列,如下所示:

select row_number() over(order by YourIdentityColumn asc)-1 as RowIndex, * from YourTable where [Expresion]

在要使用的命令控件中,使 CommandArgument 属性的值等于 DataSet 表 RowIndex 的行索引,如下所示:

<asp:LinkButton ID="lbnMsgSubj" runat="server" Text='<%# Eval("MsgSubj") %>' Font-Underline="false" CommandArgument='<%#Eval("RowIndex") %>' />

使用 OnRowCommand 事件来单击链接按钮时会像这样触发:

<asp:GridView ID="gvwStuMsgBoard" runat="server" AutoGenerateColumns="false" GridLines="Horizontal" BorderColor="Transparent" Width="100%" OnRowCommand="gvwStuMsgBoard_RowCommand">

最后,当事件被触发时,您后面的代码就可以做任何您喜欢的事情,如下所示:

protected void gvwStuMsgBoard_RowCommand(object sender, GridViewCommandEventArgs e)
{
    Panel pnlMsgBody = (Panel)gvwStuMsgBoard.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("pnlMsgBody");
    if(pnlMsgBody.Visible == false)
    {
        pnlMsgBody.Visible = true;
    }
    else
    {
        pnlMsgBody.Visible = false;
    }
}

If your GridView is databond, make an index column in the resultset you retrive like this:

select row_number() over(order by YourIdentityColumn asc)-1 as RowIndex, * from YourTable where [Expresion]

In the command control you want to use make the value of CommandArgument property equal to the row index of the DataSet table RowIndex like this:

<asp:LinkButton ID="lbnMsgSubj" runat="server" Text='<%# Eval("MsgSubj") %>' Font-Underline="false" CommandArgument='<%#Eval("RowIndex") %>' />

Use the OnRowCommand event to fire on clicking the link button like this:

<asp:GridView ID="gvwStuMsgBoard" runat="server" AutoGenerateColumns="false" GridLines="Horizontal" BorderColor="Transparent" Width="100%" OnRowCommand="gvwStuMsgBoard_RowCommand">

Finally the code behind you can then do whatever you like when the event is triggered like this:

protected void gvwStuMsgBoard_RowCommand(object sender, GridViewCommandEventArgs e)
{
    Panel pnlMsgBody = (Panel)gvwStuMsgBoard.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("pnlMsgBody");
    if(pnlMsgBody.Visible == false)
    {
        pnlMsgBody.Visible = true;
    }
    else
    {
        pnlMsgBody.Visible = false;
    }
}
甜心 2024-12-04 03:13:12
string textboxID;
string da;
textboxID = "ctl00$MainContent$grd$ctl" + (grd.Columns.Count + j).ToString() + "$txtDyna" + (k).ToString();
textboxID= ctl00$MainContent$grd$ctl12$ctl00;
da = Request.Form(textboxID);
string textboxID;
string da;
textboxID = "ctl00$MainContent$grd$ctl" + (grd.Columns.Count + j).ToString() + "$txtDyna" + (k).ToString();
textboxID= ctl00$MainContent$grd$ctl12$ctl00;
da = Request.Form(textboxID);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文