Need help in gridview displaying data
Posted
by
sumit
on Stack Overflow
See other posts from Stack Overflow
or by sumit
Published on 2009-07-22T06:43:40Z
Indexed on
2010/12/24
5:54 UTC
Read the original article
Hit count: 420
Hi all, I want to display all the data in gridview which i am inserting in runtime. For that i have written code but getting this error.
"Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition."
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
public void BindData()
{
string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
SqlConnection con = new SqlConnection(str);
SqlDataAdapter da = new SqlDataAdapter("select * from Items where ItemId='" + TxtItemId.Text + "'", con);
DataSet ds = new DataSet();
da.Fill(ds,"Items");
GridView1.DataSource = ds;
GridView1.DataBind();
}
Pls modify my code where is my mistake.
Thanks, Sumit
© Stack Overflow or respective owner