如何在单击按钮时从服务器端的转发器获取值

发布于 2024-12-06 16:51:58 字数 955 浏览 5 评论 0原文

   <asp:Repeater ID="rptList" runat="server">
                         <HeaderTemplate>
                         </HeaderTemplate>
                         <ItemTemplate>
                             <tr>
                                 <td width="15%">
                                     <b>Subject</b>
                                 </td>
                                 <td width="60%">
                                     <%#Eval("Title")%>
                                 </td>
                             </tr>

我将数据绑定到转发器,并绑定标题值。

 string MysqlStatement = "SELECT Title, RespondBy FROM tbl_message WHERE MsgID = @Value1";
        using (DataServer server = new DataServer())
        {
            ..        }
        rptList.DataSource = ds;
        rptList.DataBind();

当在同一页面中单击按钮时,如何获取服务器端标题的值。

   <asp:Repeater ID="rptList" runat="server">
                         <HeaderTemplate>
                         </HeaderTemplate>
                         <ItemTemplate>
                             <tr>
                                 <td width="15%">
                                     <b>Subject</b>
                                 </td>
                                 <td width="60%">
                                     <%#Eval("Title")%>
                                 </td>
                             </tr>

I do databind to a repeater, and bind the title value.

 string MysqlStatement = "SELECT Title, RespondBy FROM tbl_message WHERE MsgID = @Value1";
        using (DataServer server = new DataServer())
        {
            ..        }
        rptList.DataSource = ds;
        rptList.DataBind();

How can I get the value of title in server side, when a button in clicked in the same page.

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

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

发布评论

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

评论(2

再见回来 2024-12-13 16:51:58

我会将标题放在服务器控件中,就像标签一样,然后您可以执行以下操作:

<asp:Repeater ID="rptList" runat="server"> 
    <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%#Eval("Title")%>' />
    </ItemTemplate>
</asp:Repeater>

然后在后面的代码中:

int itemIndex = 0;

Label lbl = rptList.Items[itemIndex].FindControl("Label1") as Label;
if (lbl != null)
{
    string labelValue = lbl.Text;
}

I would put the title in a server control, like a label, and then you can do something like this:

<asp:Repeater ID="rptList" runat="server"> 
    <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%#Eval("Title")%>' />
    </ItemTemplate>
</asp:Repeater>

And then in the code behind:

int itemIndex = 0;

Label lbl = rptList.Items[itemIndex].FindControl("Label1") as Label;
if (lbl != null)
{
    string labelValue = lbl.Text;
}
夏至、离别 2024-12-13 16:51:58

我会将 title 的值设置为您可以调用 FindControl() 的标签的文本。

I would set the value of title to the text of a label that you could call FindControl() on.

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