-1

我需要将从数据列表中选择的链接按钮的值分配给标签。

我怎样才能做到这一点?

.aspx 代码

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" 
                style="margin-left: 5px" 
            onselectedindexchanged="DataList1_SelectedIndexChanged">
        <ItemTemplate>
            <asp:LinkButton ID="LinkButton2" runat="server" Text='<%# Eval("Description") %>' Font-Underline="False" ForeColor="Black" Font-Italic="False" ToolTip="click to open"></asp:LinkButton>
            <br />
            </ItemTemplate>
        </asp:DataList>


        <br />
        <asp:Label ID="item" runat="server" Text="Label"></asp:Label>

.aspx.cs

 protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{
    item.Text = DataList1.SelectedIndex.ToString();
}
4

2 回答 2

0

尝试以下操作:

protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{
    var myLink = DataList1.SelectedItem.FindControl("LinkButton2") as LinkButton;
    if (myLink != null)
    {
        item.Text = myLink.Text;
    }
}
于 2013-05-01T07:42:29.263 回答
0

这可以这样做:

<asp:Label1 ID="Label1" runat="server" 

Text='<%# Bind("your datafield") %>'
于 2013-05-01T07:36:41.830 回答