如何在网站的gridview中显示表格 [英] how to show table in gridview of website

查看:64
本文介绍了如何在网站的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.

推荐答案

如果你有在.aspx页面中使用任何源绑定。尝试删除您在设计页面中指​​定的数据源并执行。



如果您仍有任何问题,请告诉我。



谢谢,

DRS
This happens if you have used any source binding in your .aspx page. Try removing the data source which you have specified in design page and execute.

Do let me know if you still have any issues.

Thanks,
DRS


首先删除
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中显示表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆