Hi @Donald Symmons,
When the ImageButton is clicked, you can first use the NamingContainer property to reference the Repeater Item.
Then use the FindControl method to reference the Label and ImageButton controls from the Repeater Item.
The modified code is as follows, other codes have not been changed.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM ImageTable"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
reptrImg.DataSource = dt;
reptrImg.DataBind();
}
}
}
}
}
}
protected void ImageButton_Click(object sender, ImageClickEventArgs e)
{
ImageButton btn = (ImageButton)sender;
RepeaterItem item = (RepeaterItem)btn.NamingContainer;
ImageButton imagebuton = (ImageButton)item.FindControl("ImageButton1");
string image = imagebuton.ImageUrl;
Label lblName = (Label)item.FindControl("LblDesc");
Session["Image"] = image;
Session["imgname"] = lblName.Text.ToString();
Response.Redirect("/infoPage.aspx");
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.