开发者

How to get value from a repeater in server side on button click

开发者 https://www.devze.com 2023-04-07 09:45 出处:网络
<asp:Repeater ID=\"rptList\" runat=\"server\"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate>
   <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开发者_如何学Python can I get the value of title in server side, when a button in clicked in the same page.


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;
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消