Cannot retrieve the values in listview in runtime

Posted by Aaryan under ASP.NET on 3/16/2012 | Points: 10 | Views : 676 | Status : [Member] | Replies : 1
<div>
<b>
<%# Eval("Name") %></b></div>
<div>
$<%# Eval("id") %></div>
<asp:button ID="Button1" text="Buy" runat="server" OnClick ="Button1_Click" />
</asp:button>

In above coding am binding the name and id in list view.. am adding a button called buy.. if i click i wanna retrieve image name and id

protected void Button1_Click(object sender, EventArgs e)
{
if (ListView1.Items.Count > 0)
{
MessageBox.Show("You click product " +);
}
}

What should be given in mesage box to show the selected image's name and id..




Responses

Posted by: Hmanjarawala on: 3/16/2012 [Member] Bronze | Points: 25

Up
0
Down
Ok then Rewrite your code as:

<div>

<b>
<%# Eval("Name") %></b></div>
<div>
$<%# Eval("id") %></div>
<asp:button ID="Button1" text="Buy" runat="server" commandname='<%# Eval("Name") %>' commandArgument='<%# Eval("Id") %>' OnClick ="Button1_Click" />
</asp:button>


and change in code behind also.

protected void Button1_Click(object sender, EventArgs e)
{
if (ListView1.Items.Count > 0)
{
string name = ((Button)sender).CommandName;
string id = ((Button)sender).CommandArgument;
MessageBox.Show("You click product " +);
}
}



Mark this as answer, if it helps you.................



Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Aaryan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response