i want to change profile picture based on selected image for this i used session for storing all image's id but when i run application it returns me first id only
how to get required id can anybody know how to do this
below is my source code:
onitemcommand="RepComment_ItemCommand" >
<%# Eval("FirstName") %> <%# Eval("LastName") %> | |
code behind is:
public partial class ViewAlbum : System.Web.UI.Page
{
Images objImages = new Images();
DataSet ds1;
int RegId,PicId;
protected void Page_Load(object sender, EventArgs e)
{
RegId = (Int32)Session["RegId"];
ds1 = objImages.GetAlbum(RegId);
lvPhotoViewer.DataSource = ds1;
lvPhotoViewer.DataBind();
AdminLogin objAdminLogin = new AdminLogin();
RepComment.DataSource = ds.Tables[0];
RepComment.DataBind();
}
protected void DataPager1_PreRender(object sender, EventArgs e)
{
lvPhotoViewer.DataSource = objImages.GetAlbum((Int32)Session["RegId"]);
lvPhotoViewer.DataBind();
}
protected void lvPhotoViewer_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
if (e.Item.FindControl("imPhoto") != null)
{
string imageurl = "Images/user1.png";
ListViewDataItem item = (ListViewDataItem)e.Item;
imageurl = (string)DataBinder.Eval(item.DataItem, "ImageName");
if (item.DataItem != null)
{
imageurl = "Pictures/" + (string)DataBinder.Eval(e.Item.DataItem, "ImageName");
}
((Image)e.Item.FindControl("imPhoto")).ImageUrl = imageurl;
}
}
}
protected void RepComment_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
if(e.Item.ItemType== ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
if (e.Item.FindControl("Image1") != null)
{
string imageurl = "Images/user1.png";
imageurl = "Pictures/" + (string)DataBinder.Eval(e.Item.DataItem, "ImageName");
((Image)e.Item.FindControl("Image1")).ImageUrl = imageurl;
}
}
}
protected void RepComment_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "SetasProfilePic")
{
int picId =(Int32) Session["PicId"];
Images objImages = new Images();
objImages.SetProfilePic(RegId, picId);
}
}
protected void lvPhotoViewer_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "Image")
{
Images objImage = new Images();
Object getPicId = objImage.GetPicId(RegId);
Session["PicId"] = getPicId;
}
}
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit ChoudharyPosted Jun 24, 2013, 8:51 AM
Now to access the command argument you can use below code:
var imageId = ((LinkButton)sender).CommandArgument.ToString();
Pankaj PandeyPosted Jun 24, 2013, 7:55 AM