Immediate help-Add to favourite

Posted by Sina under ASP.NET on 6/14/2012 | Points: 10 | Views : 873 | Status : [Member] | Replies : 3
Hi i have a problem..I have a linkbutton in a repeater and many titles.The user should be able to add to his favourites on clicking the linkbutton for the particular title..My problem is only the first 'add to favourite' link works. Pl help me . Thanks in advance.

@Sina


Responses

Posted by: Dipakagarwal on: 6/14/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Sina, plz paste your code here so that i can understand your problem clearly...

Dipak Agarwal

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

Posted by: Sina on: 6/14/2012 [Member] Starter | Points: 25

Up
0
Down

protected void Rpt_ItemCreated(object sender, RepeaterItemEventArgs e)
{
string user = "";
if (Session["UserId"] != null)
user = Session["UserId"].ToString();
if (e.Item.ItemType == ListItemType.Item)
{
Label lblDealid = e.Item.FindControl("lblDealid") as Label;
//lblDealid.Text = DataBinder.Eval(e.Item.DataItem).ToString();
LinkButton lnkFav = e.Item.FindControl("lnkFav") as LinkButton;
lnkFav.CommandName = "Display";
lnkFav.CommandArgument = "argument";
if (lnkFav != null)
{

lnkFav.Click += delegate
{
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "insert into Favourite(Titleid,UserId) values (@titleid,@userid)";
cmd.Parameters.AddWithValue("@Titleid", lblTitleid.Text);
cmd.Parameters.AddWithValue("@userid", user);
cmd.CommandType = System.Data.CommandType.Text;
cmd.ExecuteNonQuery();
con.Close();
Response.Write("added to fav");
};
}
}
}

@Sina

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

Posted by: Sina on: 6/14/2012 [Member] Starter | Points: 25

Up
0
Down
Pl someone help me..its urgent

@Sina

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

Login to post response