0

我有一个嵌套的gridview,我想获取第一个gridview 的值并将其分配给按钮的commandArgument。有人可以建议怎么做

正如您将在下面的代码中看到的那样,我已经使用以下代码获取行索引:“ Text="Save Changes" />

我需要的是 DataField="name"

请参阅下面的完整代码。

        <script language="javascript" type="text/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 = "Images/Icons/minus.jpg";
                } else { div.style.display = "none"; img.src = "Images/Icons/plus.jpg"; }
            }</script>
        <asp:DropDownList ID="DateSelection" runat="server" AutoPostBack="True" Height="21px"
            Width="134px">
        </asp:DropDownList>
        <asp:GridView ID="GV_SL" runat="server" OnRowDataBound="gvUserInfo_RowDataBound"
            OnRowCommand="GV_SL_RowCommand" AutoGenerateColumns="False" 
            DataSourceID="SQL_Weekly" AllowSorting="True">
            <Columns>
                <asp:TemplateField ItemStyle-Width="50px">
                    <ItemTemplate>
                        <a href="JavaScript:divexpandcollapse('div<%# Eval("name") %>');">
                            <img id="imgdiv<%# Eval("name") %>" width="15px" border="0" src="Images/Icons/plus.jpg" /></a></ItemTemplate>
                    <ItemStyle Width="40px" />
                </asp:TemplateField>
                <asp:BoundField DataField="name" HeaderText="Group" SortExpression="name" />
                <asp:BoundField DataField="ASL" HeaderText="SL% Act" ReadOnly="True" SortExpression="ASL" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <tr>
                            <td colspan="100%">
                                <div id="div<%# Eval("name") %>" style="display: none; position: relative; left: 15px;
                                    overflow: auto">
                                    <asp:GridView ID="gvChildGrid" runat="server" AutoGenerateColumns="false">
                                        <Columns>
                                            <asp:BoundField DataField="Metric" HeaderText=" " HeaderStyle-HorizontalAlign="Left" />
                                            <asp:BoundField DataField="Actual" HeaderText="Actual" HeaderStyle-HorizontalAlign="Left" />
                                        </Columns>
                                    </asp:GridView>
                                    <br />
                                    <asp:UpdatePanel ID="UP_SecondPanel" runat="server" UpdateMode="Always" >
                                        <ContentTemplate>
                                            <%--  --%>
                                            <asp:TextBox ID="TB_Comments" runat="server" Text="Example: Text will be entered here"
                                                TextMode="MultiLine" Rows="4" Width="510px"></asp:TextBox>
                                            <asp:Button ID="B_Save" runat="server" CommandName="AddText" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>"
                                                Text="Save Changes" />
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                    <%--  --%>
                                </div>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

任何想法都会受到赞赏

谢谢

4

1 回答 1

0

我用VB代码对问题进行了排序。如果它对某人有帮助,请参见下文

Protected Sub GV_SL_RowCommand(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
    If (e.CommandName = "AddText") Then
        ' Retrieve the row index stored in the CommandArgument property.
        Dim index As Integer = Convert.ToInt32(e.CommandArgument)

        ' Retrieve the row that contains the button 
        ' from the Rows collection.
        Dim row As GridViewRow = GV_SL.Rows(index)
        Dim GroupName As String = GV_SL.Rows(index).Cells(1).Text

        'Rest of the code here

    End If
End Sub
于 2013-09-26T13:12:18.793 回答