2013-03-29 37 views
1

我有一个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;} 

回答

1

你可以用这个:

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

NaimingContainer是按钮所在的行。然后在里面找到你需要的ID的控件。