Blog

Display Image in gridview from the path which is in database

Posted by Hiren Soni Blogs | ASP.NET Programming Aug 19, 2010
Display Image in gridview. and the path is stored in the databse.

  

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "false"    Font-Names = "Arial" >

    <Columns>

       <asp:ImageField DataImageUrlField=" imagepath " ControlStyle-Width="100"        ControlStyle-Height = "100" HeaderText = "Preview Image"/>   

    </Columns>

    </asp:GridView>

 

 

   DataTable dt = new DataTable();

 

        String strConnString = "your connectionsting";

       

        string strQuery = "select imagepath from table1";

 

        SqlConnection con = new SqlConnection(strConnString);

        SqlCommand cmd = new SqlCommand(strQuery,con);

        SqlDataAdapter sda = new SqlDataAdapter();

            con.Open();

            sda.SelectCommand = cmd;

            sda.Fill(dt);

            GridView1.DataSource = dt;

            GridView1.DataBind();

            con.Close();

 

COMMENT USING
PREMIUM SPONSORS
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.