【问题标题】:Assign value of nested gridview into CommandName将嵌套网格视图的值分配给 CommandName
【发布时间】:2013-09-26 10:18:59
【问题描述】:

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

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

我需要的是 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>

任何想法都会被欣赏

谢谢

【问题讨论】:

    标签: asp.net vb.net gridview webforms


    【解决方案1】:

    我用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 2013-09-03
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多