How to show image in grideview from database Sql server
How to show image
in grideview from database Sql server
For this you just
bind grideview coloum from table name
Like
'<%# Bind("Name") %>'> this code is useful to bind data from table
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="False"
Height="50px" CellPadding="4" ForeColor="Black" GridLines="None" Width="588px" ShowHeader="False"
Font-Bold="False"
Font-Size="Small"
Font-Strikeout="False" onselectedindexchanged="GridView1_SelectedIndexChanged" AllowPaging="True" onpageindexchanged="GridView1_PageIndexChanged" onpageindexchanging="GridView1_PageIndexChanging">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table>
<tr>
<td rowspan="4">
<asp:Image ID="Image1" runat="server"
ImageUrl =
'<%# Eval("ImagePath") %>' Width="75px" />
</td>
<td>
<asp:Label ID="Label1" runat="server"
Text='<%#
Bind("Name") %>'></asp:Label></td>
<td rowspan="4">Address:- <asp:Label ID="Label2" runat="server"
Text='<%#
Bind("Address") %>'></asp:Label></td>
</tr>
<tr>
<td>Contact:- <asp:Label ID="Label3" runat="server"
Text='<%#
Bind("Contact") %>'></asp:Label></td>
</tr>
<tr>
<td>Class:- <asp:Label ID="Label4" runat="server"
Text='<%#
Bind("ClassName") %>'></asp:Label></td>
</tr>
<tr>
<td>City:- <asp:Label ID="Label5" runat="server"
Text='<%#
Bind("City") %>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#66CCFF" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
protected void Button2_Click(object sender, EventArgs e)
{
connection = ConfigurationSettings.AppSettings["con"].ToString();
SqlConnection con = new SqlConnection(connection);
con.Open();
string ret = "select Name,Address,Contact,City,ImagePath,ClassName from SearchData where Sector = '" + DropDownList1.SelectedItem + "' and ClassName = '" + DropDownList2.SelectedItem + "'";
cmd = new SqlCommand(ret, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
No comments :
Post a Comment