views:

102

answers:

2

I need to access a label control in a listview when i've clicked a button (that is on the same row)...

Does anyone know how to do this please? :(

See below for more of an insight...

ASPX Page:

<asp:ListView ID="ListView1" runat="server" DataSourceID="DataSource">
<LayoutTemplate>//Etc </LayoutTemplate>
<ItemTemplate>
<asp:Label ID="lblDone" runat="server" Visible="false">Your vote has been counted</asp:Label>
<asp:Button ID="voteButton" runat="server" Text="Vote" CommandArgument='<%#Eval("id") %>' OnClick="voteOnThis" />
</ItemTemplate>

Code Behind:

protected void voteOnThis(object sender, EventArgs e)
{
    Button myButton = (Button)sender;
    Voting.vote(int.Parse(myButton.CommandArgument));
    // Here i would like to access the 'label' lblDone and make this Visible    
}
A: 

You need to hook into the listview row bind and add the information you want to have when clicked. Using this, you can add an attribute to the button that you read back on click, for example...

If you posted some actual code, I could probably help some more.

BenB
A: 

have you try findcontrol??? like...

Label lbl = (Label)yourListView.FindControl("yourlable");
Muhammad Akhtar