本文介绍了如何在网站的gridview中显示表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Button2_Click1(object sender,EventArgs e)

{

SqlConnection con = new SqlConnection(@Data Source = ABHINAV-PC\ABHI; Initial Catalog = swapnil; Integrated Security = True);

con.Open();

if(DropDownList1.SelectedIndex == 0)

{

SqlDataAdapter da = new SqlDataAdapter(select * from Biscuits,con);

DataSet ds = new DataSet();

da。填充(ds);

GridView1.DataSource = ds;

}

else if(DropDownList1.SelectedIndex == 1)

{

SqlDataAdapter da = new SqlDataAdapter(select * from oil,con);

DataSet ds = new DataSet();

da.Fill(ds);

GridView1.DataSource = ds;

}

当我运行它给出的代码时错误为

protected void Button2_Click1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=ABHINAV-PC\ABHI;Initial Catalog=swapnil;Integrated Security=True");
con.Open();
if (DropDownList1.SelectedIndex == 0)
{
SqlDataAdapter da = new SqlDataAdapter("select * from Biscuits",con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
}
else if(DropDownList1.SelectedIndex == 1)
{
SqlDataAdapter da = new SqlDataAdapter("select * from oil", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
}
when i am running the code it is giving error as

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Both DataSource and DataSourceID are defined on 'GridView1'.  Remove one definition.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

推荐答案


DataSourceID 

来自ASPX设计师页面的gridview .. :)



from gridview from ASPX designer page.. :)

protected void Button2_Click1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=ABHINAV-PC\ABHI;Initial Catalog=swapnil;Integrated Security=True");
con.Open();
if (DropDownList1.SelectedIndex == 0)
{

string SelectData="select * from Biscuits";
}
else if(DropDownList1.SelectedIndex == 1)
{
string SelectData="select * from oil";

}
SqlDataAdapter da = new SqlDataAdapter(SelectData,con);
DataTable dt = new DataTable ();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();


这篇关于如何在网站的gridview中显示表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 04:22
查看更多