开发者

How can i access a control within a ListView once a button has been clicked?

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:Butt开发者_C百科on 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    
}


In this simple case, I should consider using Javascript (JQuery)

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

now, define inside a script tag the showLblDone function:

<script>
function showLblDone (){
$(this).siblings('span').show();}
</script>

You can also call this function with a parameter if you want to show/hide on every click, or you can use .toggle() instead of .show().

In this case you must add a div (or a Panel) inside the ItemTemplate.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜