Bahar Jalali

Bahar Jalali

  • NA
  • 185
  • 305.5k

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

Nov 22 2009 6:46 AM
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)