【问题标题】:access dropdown selected item inside of gridview访问gridview内的下拉选定项目
【发布时间】:2013-03-29 12:38:53
【问题描述】:

我有一个Gridview 有一个下拉灯和按钮。现在我想在button click上获取dropdown列表的选定值。这是我的示例代码

<asp:TemplateField>
                    <ItemTemplate>
                        <asp:DropDownList ID="ddPStatud" runat="server" DataSourceID="sdsProductStatus" DataTextField="StatusName"
                            DataValueField="StatusId">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="sdsProductStatus" runat="server" ConnectionString="<%$ ConnectionStrings:cs %>"
                            SelectCommand="SelectProductStatus" SelectCommandType="StoredProcedure">
                            <SelectParameters>
                                <asp:SessionParameter Name="Branchid" SessionField="Branchid" Type="Int16" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </ItemTemplate>
                </asp:TemplateField>

这是按钮

<asp:TemplateField>
                    <ItemTemplate>
                        <asp:Button ID="tst" runat="server" Text="text" CommandName="Test" CommandArgument='<%# Eval("EntryID") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>

这是RowCommand函数

if (e.CommandName == "Test")
            {
                String row = e.CommandArgument.ToString();
                lblError.Visible = true;
                lblError.Text = row;}

【问题讨论】:

    标签: asp.net gridview drop-down-menu itemtemplate


    【解决方案1】:

    你可以用这个:

    DropDownList dll = (DropDownList)((Control)e.CommandSource).NamingContainer.FindControl("ddPStatud");
    String selectedValue = dll.SelectedValue;
    

    NaimingContainer 是按钮所在的行。然后在其中找到具有所需 ID 的控件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多