Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
public static void BindGridView(string qr, GridView grd)
   {
       //con = new SqlConnection(connectionstring);
       //openconnection();

       dap = new SqlDataAdapter(qr, con);
       DataSet ds = new DataSet();
       dap.Fill(ds);
       grd.DataSource = ds.Tables[0].DefaultView;
       grd.DataBind();  //it is generating error at this function of binding.

   }
Posted
Comments
AshishChaudha 14-Aug-12 3:22am    
what error???
ankur15 14-Aug-12 3:25am    
it is giving the data binding error that i have binded in data field by Eval("") function.

Hi ,
Check this
it's working with me
C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           BindGridView("select * from ODetails", GridView1);
           GridView1.DataBind();
       }
   }
   SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString);
   SqlDataAdapter dap;
   void BindGridView(string qr, GridView grd)
   {
       //con = new SqlConnection(connectionstring);
       //openconnection();

       dap = new SqlDataAdapter(qr, con);
       DataSet ds = new DataSet();
       dap.Fill(ds);
       grd.DataSource = ds.Tables[0].DefaultView;
       grd.DataBind();  //it is generating error at this function of binding.

   }

Best Regards
M.Mitwalli
 
Share this answer
 
Comments
Prasad_Kulkarni 16-Aug-12 2:11am    
Good work +5!
Mohamed Mitwalli 16-Aug-12 4:30am    
Thank you Prasad :)
C#
Dataset objdatset = new dataset();
sqlconnection objcon = new sqlconnection(" ");
sqldataadapter objdataadpter = new sqldatadapter(" select * from emp",objcon);
objadapter.fill(objdataset,"Emp");
gridview1.datasource=objdataset;
gridivew.databind();

check for this should works... thankz..
 
Share this answer
 
v2
Comments
ankur15 14-Aug-12 3:42am    
but i m using a bussiness class for connectivity the database... so
Abdul Quader Mamun 14-Aug-12 3:58am    
nice and easy answer but question was not clear!
ankur15 14-Aug-12 4:33am    
don worry i have resolve my problem... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900