user3417203
user3417203

Reputation: 23

How to display an image in a GridView control

I am trying to show the database from SQL Server to a GridView using C# and wanted to show the image within the control. I am using the code below to show the database.

protected void txtsinglesearch_TextChanged(object sender, EventArgs e)
{
    if (DropDownList1.SelectedItem.Text == "First Name")
    {  
        string q = "select * from facultyreg where fname like'" + txtsinglesearch.Text.ToString() + "%' ";
        sda = new SqlDataAdapter(q, con);
        ds = new DataSet();
        sda.Fill(ds, "facultyreg");
        grdvw_sigsrch_by_name.DataSource = ds.Tables[0];
        grdvw_sigsrch_by_name.DataBind();
    }
}

This code is inside the TextChanged event of TextBox where I am searching the initial letter from the database and display the result in the GridView

Upvotes: 0

Views: 403

Answers (1)

huMpty duMpty
huMpty duMpty

Reputation: 14460

You can use TemplateFields

e.g.

<asp:TemplateField HeaderText="Title">
   <ItemTemplate>
        <asp:Image runat="server" ID="Img" ImageUrl='<%# Eval("yourImagepath")%>' />
   </ItemTemplate>
</asp:TemplateField> 

Or there is an example of Displaying Images in a GridView Column

Upvotes: 4

Related Questions