Image in a gridview
-
i m trying to display the Images in a grid view with refrence to the following article it is the article if Abhijit Jana on code project but i m getting the following errors error: Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition. in the following lines GridView1.DataSource = ds; // give data to gridview GridView1.DataBind(); can anyone help me ??
-
i m trying to display the Images in a grid view with refrence to the following article it is the article if Abhijit Jana on code project but i m getting the following errors error: Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition. in the following lines GridView1.DataSource = ds; // give data to gridview GridView1.DataBind(); can anyone help me ??
swtlibra wrote:
it is the article if Abhijit Jana on code project
Yes I am on Code Project . UP and Running :laugh:
swtlibra wrote:
error: Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition. in the following lines GridView1.DataSource = ds; // give data to gridview GridView1.DataBind();
Because, I guess, You are using Two Data Source for GridView1. One From Code Behind. and Another is on ASPX PAge. As per my article goes, Displaying Image in Gridview from Database[^] There is only one datasource that is created only on CodeBehind. Remove DataSourceID of GridView From aspx page.
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
i m trying to display the Images in a grid view with refrence to the following article it is the article if Abhijit Jana on code project but i m getting the following errors error: Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition. in the following lines GridView1.DataSource = ds; // give data to gridview GridView1.DataBind(); can anyone help me ??
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/
-
swtlibra wrote:
it is the article if Abhijit Jana on code project
Yes I am on Code Project . UP and Running :laugh:
swtlibra wrote:
error: Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition. in the following lines GridView1.DataSource = ds; // give data to gridview GridView1.DataBind();
Because, I guess, You are using Two Data Source for GridView1. One From Code Behind. and Another is on ASPX PAge. As per my article goes, Displaying Image in Gridview from Database[^] There is only one datasource that is created only on CodeBehind. Remove DataSourceID of GridView From aspx page.
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
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/
-
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/
:jig:
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
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/
-
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.
-
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.
<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
-
<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
put a breakpoint at GridView1.DataSource = ds; and check if ds is filling correctly with data.
Arun Jacob http://codepronet.blogspot.com/
-
put a breakpoint at GridView1.DataSource = ds; and check if ds is filling correctly with data.
Arun Jacob http://codepronet.blogspot.com/
-
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
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/
-
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/
-
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/
-
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.