Errors while binding the data

When you are using DropDownList or GridView, when you specify the DataSource you should bind the control, otherwise the data will not be displayed in the control.


DropDownList1.DataSource=datasource1;

After this you should specify

DropDownList1.DataBind();

You should bind the data to the control.

This is applicable for all the controls.

similarly, for GridView when you specify the DataSource you should bind the GridView control.

GridView1.DataSource=datasource2;
GridView1.DataBind();


Comments

Author: srinadh chowdary07 May 2009 Member Level: Gold   Points : 1

hi,

For all the controls we need to give databind() exceptt for the text box.

With Regards
Srinadh

Author: Deepa28 Nov 2009 Member Level: Bronze   Points : 1

Bind the datasouce to GridView Control

SqlDataAdapter sqlAdapter=new SqlDataAdapter();

DataTable dtUsers=new DataTable();
sqlAdapter.Fill(dtUsers);

if(dtUsers.Rows.count>0)
{
GridView1.DataSource=dtUsers;
GridView1.DataBind();
}

You can Bind all controls to this way except textbox.


Author: subhashinichoudhary27 Dec 2009 Member Level: Gold   Points : 1

sqlconnection con=new sqlconnection("connectionpath");
con.open();
sqlcommand cmd=new sqlcommand("query",con);
sqldataadapter da=new sqldataadapter(cmd);
Dataset ds=new Dataset();
da.fill(ds);
Gridview1.datasource=ds.Tables(0);
Giidview1.databind();

Author: mithun29 Dec 2009 Member Level: Bronze   Points : 1

sqlconnection con=new sqlconnection("path");
con.open();
sqlcommand cmd=new sqlcommand("query",con);
sqldataadapter da=new sqldataadapter(cmd);
Dataset ds=new Dataset();
da.fill(ds);
GridviewId.datasource=ds.Tables(0);
GiidviewId.databind();

Author: Jayendra Kumar24 Feb 2010 Member Level: Gold   Points : 1

Data Binding is compulsory to display the records from database to control except textbox.

Author: shashi shekhar02 Apr 2010 Member Level: Bronze   Points : 2

When we are using any data control in asp.net we need to assign Data Source Property and Databind Method. not in windows Application.

Code


SqlConnection con = new SqlConnection(" data source=shashi;initial catalog=employee;integrated security=true");
SqlDataAdapter da = new SqlDataAdapter("select * from Employee", con);
DataTable dt = new DataTable();
dt.Rows.Clear();
da.Fill(dt);

/*When we are using GridView Control in ASP.NET*/
GridView1.DataSource = dt;
GridView1.DataBind();
/*if using DropdownList in ASP.NET*/

DropDownList1.DataSource = dt;
DropDownList1.DataTextField="Emp_name"
// Emp_name is The Column Name of DataTable
DropDownList1.DataValueField="Emp_Code";
// Emp_Code is The Column Name of DataTable
DropDownList1.DataBind();

Author: nirav14 Apr 2010 Member Level: Gold   Points : 2

for binding data with drop down u have to code like this

DropDownList1.DataSource = ds;
DropDownList1.DataTextField="EmpName"

DropDownList1.DataValueField="EmpID";

DropDownList1.DataBind();


gor gridview

gridView1.Datasource =ds
gridView1.Databind()




* note: where ds as dataset



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: