调用中继器内的按钮或下拉列表

发布于 2024-11-09 03:55:22 字数 1225 浏览 0 评论 0原文

我在repeater内有一个labeldropdownlist。当我单击转发器外部的按钮时,我想访问 label.Text 值和 ddl.SelectedIndex 值。

<asp:Repeater ID="rptProduct" runat="server" DataSourceID="objdsProduct" OnItemCommand="rptProduct">
   <ItemTemplate>
   <div>
      <div>
         <asp:Label ID="lblProdName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
      </div>
      <div>
         <asp:DropDownList ID="ddlSize" runat="server" AutoPostBack="False" DataSourceID="objdsSize"  DataTextField="SizeName" AppendDataBoundItems="True" DataValueField="SizeID">
            <asp:ListItem Text="select a size" Value=0></asp:ListItem>
         </asp:DropDownList>
   </div>
   </ItemTemplate>
</asp:Repeater>

<asp:Button ID="btnChoose" runat="server" Text="Choose Products" />

有关如何访问 lblProdName.TextddlSize.SelectedValue 的任何建议:

Protected Sub btnChoose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnChoose.Click

   Dim ProductName
   Dim Size

End Sub

感谢您的宝贵时间。

I have a label and dropdownlist inside a repeater. When I click a button outside the repeater I would like to access the label.Text value and ddl.SelectedIndex value.

<asp:Repeater ID="rptProduct" runat="server" DataSourceID="objdsProduct" OnItemCommand="rptProduct">
   <ItemTemplate>
   <div>
      <div>
         <asp:Label ID="lblProdName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
      </div>
      <div>
         <asp:DropDownList ID="ddlSize" runat="server" AutoPostBack="False" DataSourceID="objdsSize"  DataTextField="SizeName" AppendDataBoundItems="True" DataValueField="SizeID">
            <asp:ListItem Text="select a size" Value=0></asp:ListItem>
         </asp:DropDownList>
   </div>
   </ItemTemplate>
</asp:Repeater>

<asp:Button ID="btnChoose" runat="server" Text="Choose Products" />

Any suggestions how I can access lblProdName.Text and ddlSize.SelectedValue within:

Protected Sub btnChoose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnChoose.Click

   Dim ProductName
   Dim Size

End Sub

Thank you for your time.

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

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

发布评论

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

评论(3

我不咬妳我踢妳 2024-11-16 03:55:22

将其添加到您的按钮点击中:

Dim item As RepeaterItem
For Each item In  rptProduct.Items
    Dim ProductName As String = DirectCast(item.FindControl("lblProdName"), Label).Text   
Dim Size As Integer = (DirectCast(item.FindControl("ddlSize"), DropDownList).SelectedValue
Next item

Add this to your button click:

Dim item As RepeaterItem
For Each item In  rptProduct.Items
    Dim ProductName As String = DirectCast(item.FindControl("lblProdName"), Label).Text   
Dim Size As Integer = (DirectCast(item.FindControl("ddlSize"), DropDownList).SelectedValue
Next item
神仙妹妹 2024-11-16 03:55:22
  Dim ProductName As String = DirectCast(rptProduct.FindControl("lblProductName"), Label).Text
  Dim Size As Integer = DirectCast(rptProduct.FindControl("ddlSize"), DropDownList).SelectedValue

但是...您如何确定要从中获取值的中继器中的哪个项目?

查看此 MSDN 页面,特别是这一点:

Sub R1_ItemCommand(Sender As Object, e As RepeaterCommandEventArgs)
    Label2.Text = "Button " & _
        Repeater1.Items(e.Item.ItemIndex).ItemIndex.ToString() & _
        " has just been clicked! <br />"
End Sub
  Dim ProductName As String = DirectCast(rptProduct.FindControl("lblProductName"), Label).Text
  Dim Size As Integer = DirectCast(rptProduct.FindControl("ddlSize"), DropDownList).SelectedValue

But ... how are you going to identify which item in the repeater you want to get the values from?

Have a look at this MSDN page, specifcally this bit:

Sub R1_ItemCommand(Sender As Object, e As RepeaterCommandEventArgs)
    Label2.Text = "Button " & _
        Repeater1.Items(e.Item.ItemIndex).ItemIndex.ToString() & _
        " has just been clicked! <br />"
End Sub
念三年u 2024-11-16 03:55:22

你必须迭代中继器行......

protected void btnChoose_Click(object sender, EventArgs e)
{
    foreach (RepeaterItem item in Repeater1.Items)
    {
       Label lblProdName = item.FindControl("lblProdName") as Label;
       lblProdName.Text .........
       DropDownList ddlSize = item.FindControl("ddlSize") as DropDownList;
       ddlSize.SelectedValue .........

    }
}

You have to iterate repeater rows....

protected void btnChoose_Click(object sender, EventArgs e)
{
    foreach (RepeaterItem item in Repeater1.Items)
    {
       Label lblProdName = item.FindControl("lblProdName") as Label;
       lblProdName.Text .........
       DropDownList ddlSize = item.FindControl("ddlSize") as DropDownList;
       ddlSize.SelectedValue .........

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文