Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Image in a gridview

Image in a gridview

Scheduled Pinned Locked Moved ASP.NET
helpcssasp-netcomquestion
14 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Arun Jacob

    Abhijit Jana wrote:

    Yes I am on Code Project . UP and Running Laugh

    swtlibra found you.lol :laugh: :laugh:

    Arun Jacob http://codepronet.blogspot.com/

    A Offline
    A Offline
    Abhijit Jana
    wrote on last edited by
    #5

    :jig:

    Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

    1 Reply Last reply
    0
    • A Arun Jacob

      swtlibra wrote:

      Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.

      Error is self describing.look at that. :) I think you defined DataSourceID in the html.Check your html for GridView and remove that. :)

      Arun Jacob http://codepronet.blogspot.com/

      S Offline
      S Offline
      swtlibra
      wrote on last edited by
      #6

      when i remove the datasource ID from gridview it dosen't display the whole grid view :(

      A 1 Reply Last reply
      0
      • S swtlibra

        when i remove the datasource ID from gridview it dosen't display the whole grid view :(

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #7

        swtlibra wrote:

        it dosen't display the whole grid view :(

        Show us the code of GriView from aspxpage. And DataBind code from Codebehind page.

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        S 1 Reply Last reply
        0
        • A Abhijit Jana

          swtlibra wrote:

          it dosen't display the whole grid view :(

          Show us the code of GriView from aspxpage. And DataBind code from Codebehind page.

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          S Offline
          S Offline
          swtlibra
          wrote on last edited by
          #8

          <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Image_ID" AllowPaging="True" onrowdatabound="GridView1_RowDataBound" onselectedindexchanged="GridView1_SelectedIndexChanged"> <Columns> <asp:BoundField DataField="Image_ID" HeaderText="Image_ID" InsertVisible="False" ReadOnly="True" SortExpression="Image_ID" /> <asp:TemplateField> <ItemTemplate> <asp:Image ID="img_1" ImageUrl='<%# Bind("Image_1") %>' runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:ImageField DataImageUrlField="Image_1"> </asp:ImageField> <asp:ImageField DataImageUrlField="Image_2"> </asp:ImageField> <asp:ImageField DataImageUrlField="Image_3"> </asp:ImageField> </Columns> </asp:GridView> using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.OleDb; using System.IO; public partial class samplepage : System.Web.UI.Page { OleDbConnection con; OleDbCommand cmd; OleDbDataReader rd; OleDbDataAdapter da; DataSet ds; //Directory.CurrentDirectory; protected void Page_Load(object sender, EventArgs e) { //Directory.CreateDirectory(@"~\Upload\"); con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("App_Data/testdb.mdb")); Load_GridData(); } void Load_GridData() { con.Open(); //open the connection OleDbDataAdapter da = new OleDbDataAdapter("select Image_ID, Image_1, Image_2, Image_3 from Images", con); DataSet ds=new DataSet(); //DataTable table = new DataTable(); da.Fill(ds); // Fill the dataset GridView1.DataSource = ds; // give data to gridview GridView1.DataBind(); con.Close(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void G

          A 1 Reply Last reply
          0
          • S swtlibra

            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Image_ID" AllowPaging="True" onrowdatabound="GridView1_RowDataBound" onselectedindexchanged="GridView1_SelectedIndexChanged"> <Columns> <asp:BoundField DataField="Image_ID" HeaderText="Image_ID" InsertVisible="False" ReadOnly="True" SortExpression="Image_ID" /> <asp:TemplateField> <ItemTemplate> <asp:Image ID="img_1" ImageUrl='<%# Bind("Image_1") %>' runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:ImageField DataImageUrlField="Image_1"> </asp:ImageField> <asp:ImageField DataImageUrlField="Image_2"> </asp:ImageField> <asp:ImageField DataImageUrlField="Image_3"> </asp:ImageField> </Columns> </asp:GridView> using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.OleDb; using System.IO; public partial class samplepage : System.Web.UI.Page { OleDbConnection con; OleDbCommand cmd; OleDbDataReader rd; OleDbDataAdapter da; DataSet ds; //Directory.CurrentDirectory; protected void Page_Load(object sender, EventArgs e) { //Directory.CreateDirectory(@"~\Upload\"); con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("App_Data/testdb.mdb")); Load_GridData(); } void Load_GridData() { con.Open(); //open the connection OleDbDataAdapter da = new OleDbDataAdapter("select Image_ID, Image_1, Image_2, Image_3 from Images", con); DataSet ds=new DataSet(); //DataTable table = new DataTable(); da.Fill(ds); // Fill the dataset GridView1.DataSource = ds; // give data to gridview GridView1.DataBind(); con.Close(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void G

            A Offline
            A Offline
            Arun Jacob
            wrote on last edited by
            #9

            put a breakpoint at GridView1.DataSource = ds; and check if ds is filling correctly with data.

            Arun Jacob http://codepronet.blogspot.com/

            S 1 Reply Last reply
            0
            • A Arun Jacob

              put a breakpoint at GridView1.DataSource = ds; and check if ds is filling correctly with data.

              Arun Jacob http://codepronet.blogspot.com/

              S Offline
              S Offline
              swtlibra
              wrote on last edited by
              #10

              ok if we use a simple code then how the image will be displayed using code through code simple data is displaying in the grid

              A 1 Reply Last reply
              0
              • S swtlibra

                ok if we use a simple code then how the image will be displayed using code through code simple data is displaying in the grid

                A Offline
                A Offline
                Arun Jacob
                wrote on last edited by
                #11

                swtlibra wrote:

                if we use a simple code then how the image will be displayed using code

                Give the path of the image as relative url and check if that images existing in the solution. :)

                Arun Jacob http://codepronet.blogspot.com/

                S 1 Reply Last reply
                0
                • A Arun Jacob

                  swtlibra wrote:

                  if we use a simple code then how the image will be displayed using code

                  Give the path of the image as relative url and check if that images existing in the solution. :)

                  Arun Jacob http://codepronet.blogspot.com/

                  S Offline
                  S Offline
                  swtlibra
                  wrote on last edited by
                  #12

                  where to give the path plz tell about the code

                  A A 2 Replies Last reply
                  0
                  • S swtlibra

                    where to give the path plz tell about the code

                    A Offline
                    A Offline
                    Arun Jacob
                    wrote on last edited by
                    #13

                    Instead of ((Image)e.Row.FindControl("img_1")).ImageUrl = "'@~/Upload/'" ; give something like, ((Image)e.Row.FindControl("img_1")).ImageUrl = @"~/Upload/imagename.jpg" ; where imagename is the path from object source. :)

                    Arun Jacob http://codepronet.blogspot.com/

                    1 Reply Last reply
                    0
                    • S swtlibra

                      where to give the path plz tell about the code

                      A Offline
                      A Offline
                      Abhijit Jana
                      wrote on last edited by
                      #14

                      swtlibra wrote:

                      where to give the path

                      Image path should be the database column . And physically your image storage location would be hard drive. When you will retrieve the path from database, image will be load from drive. The Article, which you have mention above, clearly explained each and every steps. :)

                      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups