5
Reply

get id of items that i click on button in a datalist with itemtemplate

Bahar Jalali

Bahar Jalali

Nov 22 2009 6:46 AM
12.7k
hi friends

i have a datalist on my page and design it on template

i have some button and image and hyperlink to it;
now i wand when i clicked a button of one item's , i can get id of that item

how can i do that?

my code is here but with some error

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = ProdID.ToString();
// ShoppungCart.GetShoppingCart().AddItem(ProdID);
// Response.Redirect("ViewCart.aspx");
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
int ProdID = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]);
}


but label1 is null and maybe ProdID is null;
why?

Answers (5)