none
asp.net

    Question

  • 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.SqlClient;
    using System.IO;
    
    namespace photoshops
    {
      public partial class WebForm2 : System.Web.UI.Page
      {
        SqlConnection conn = new SqlConnection();
        protected void Page_Load(object sender, EventArgs e)
        {
          conn.ConnectionString
           = @"Data Source=DEVI\SQLEXPRESS; Initial Catalog =cat; Integrated Security=SSPI";
    
          Load_GridData(); // call method below
        }
        void Load_GridData()
        {
          conn.Open(); // open the connection 
          SqlDataAdapter Sqa = new SqlDataAdapter("select * from tblphotosettings", conn);
          DataSet ds = new DataSet();
          Sqa.Fill(ds);  // fill the dataset 
          GridView1.DataSource = ds; // give data to GridView
          GridView1.DataBind();
          conn.Close();
        }
    
        protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
    
        }
      }
    }
    
    i want display image and customer record but error
    Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.
    • Moved by Paul Zhou Tuesday, April 26, 2011 3:38 AM off-topic (From:.NET Base Class Library)
    Thursday, April 14, 2011 6:32 AM

Answers

  •  

    Hi,

     

    According to your description, I'd like to move your thread to off-topic because it is a problem related to ASP.NET. You may post thread in ASP.NET Forum. There are more experts in that forum so that you may get more useful help there.

     

    Thank you for your posting and understanding.

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 26, 2011 3:38 AM

All replies

  • Change the Load_GridData as below

        void Load_GridData()
        {
              conn.Open(); // open the connection
              SqlDataAdapter Sqa = new SqlDataAdapter("select * from tblphotosettings", conn);
              DataSet ds = new DataSet();
              Sqa.Fill(ds);  // fill the dataset
              GridView1.DataSource = ds.Tables[0]; // give data to GridView
              conn.Close();
        }


    Please mark this post as answer if it solved your problem. Happy Programming!
    Thursday, April 14, 2011 9:01 AM
  • you need to provide either DataSouceID or DataSouce

    Remove DataSourceID property from you gridview definition in aspx page. I will resolve you problem

    Also if you want to display images against some values you need to take template field and vary its visibility based on data coming easy way is to databound event.

    Thursday, April 14, 2011 10:21 AM
  • Hi Error is coming because i think u have given DatasourceId inside the gridview tag on aspx page . First remove it from there otherwise u need to put datasource control on ur page with the same id u have given on for gird view.

    And if u want to display image in ur grid view then plz add a template field in ur gridview and then drag and drop the image control inside  that template. now u will give the path to the image to display. Thats all.

    Thanks and please if it solves ur prob then plz mark it as answer.

     


    amit.murli
    Thursday, April 14, 2011 12:47 PM
  • Hi,

     

    As everybody said you are trying to bind two set of data to one gridview. So use either one Datasource id or datasource. Datasource id is nothing but pointing to another data source.

    But for some reason (not sure why) you want to keep the id in the markup then you can nullify it from codebehind bysetting GridView1.DataSourceId=null; and then assign your  new datasource to it.

     

    Another thing once you passed the connection to the SqlDataAdapter, then no need to open and close the connection explicitly. The adapter do it for you. :)

    Thursday, April 14, 2011 1:38 PM
  • but error

    Source Error:

     
    Line 25:   <div>
    Line 26:   
    Line 27:     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    Line 28:       ConnectionString="<%$ ConnectionStrings:catConnectionString %>" 
    Line 29:       onselecting="SqlDataSource1_Selecting" 

     

    Friday, April 15, 2011 7:37 AM
  • please send the complete error it will be help full to me so that i can understand the exact error.
    amit.murli
    Friday, April 15, 2011 8:04 AM
  • or u do not need ko give datasource form the code behind beacuse u r given it through aspx page
    amit.murli
    Friday, April 15, 2011 8:06 AM
  • Earlier you are having error in the gridview and now in the datasource. The error in the datasource is independent of the earlier post. Could you post more details of the error?
    Friday, April 15, 2011 9:36 AM
  •  

    Hi,

     

    According to your description, I'd like to move your thread to off-topic because it is a problem related to ASP.NET. You may post thread in ASP.NET Forum. There are more experts in that forum so that you may get more useful help there.

     

    Thank you for your posting and understanding.

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 26, 2011 3:38 AM