TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ajit N
NA
352
71.1k
How to Show Image on gridview image button click event ?
Jun 29 2019 2:44 AM
Hello, I want to show image in new tab when i click on particular image button in GridView. i tried some code which i mentioned below,but it didn't work for me. so help me how can i do this.
Front End Code :
<asp:GridView ID=
"GridView1"
runat=
"server"
CssClass=
"table table-bordered table-hover"
DataKeyNames=
"ID"
OnRowCommand=
"GridView1_RowCommand"
OnSelectedIndexChanged=
"GridView1_SelectedIndexChanged"
EmptyDataText=
"No records has been added."
AutoGenerateColumns=
"False"
>
<Columns>
<asp:BoundField DataField=
"ID"
HeaderText=
"ID"
/>
<asp:TemplateField HeaderText=
"Photo"
>
<ItemTemplate>
<asp:ImageButton ID=
"imgRedirect"
runat=
"server"
Height=
"50px"
Width=
"50px"
ImageUrl=
'<%# Eval("img") %>'
OnClick=
"imgRedirect_Click"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Backend Code :
protected
void
imgRedirect_Click(
object
sender, ImageClickEventArgs e)
{
int
getid = Convert.ToInt32(GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text);
string
imagename =
string
.Empty;
con.Open();
SqlCommand cmd =
new
SqlCommand(
"select * from AddPrescription where ID='"
+ getid +
"'"
, con);
SqlDataReader dr = cmd.ExecuteReader();
if
(dr.Read())
{
imagename = dr[
"img"
].ToString();
}
con.Close();
Response.Redirect(imagename);
}
Reply
Answers (
1
)
reading xml document as attribute name and attirbute value
Error : Incorrect syntax near the keyword 'Table'." ?