我想在点击按钮后在gridview中按升序显示行。请帮我 [英] I want to display rows in ascending order in gridview after clicking on button. Please help me

查看:77
本文介绍了我想在点击按钮后在gridview中按升序显示行。请帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在点击按钮后以gridview中的升序显示行。请帮帮我,这是代码。



protected void Button2_Click(object sender,EventArgs e)

{

try

{

DataTable dt = new DataTable();

Dbconn.Open();

string str =select id,dte from通过id asc测试订单;

oda =新的OracleDataAdapter(str,Dbconn);

oda.Fill(dt);



GridView1.DataBind();



}



catch(Exception ex)

{



}

}



我尝试过:



protected void Button2_Click(object sender,EventArgs e)

{

尝试

{

DataTable dt = new DataTable();

Dbconn.Open();

string str =select id,dte fro通过id asc测试订单;

oda =新的OracleDataAdapter(str,Dbconn);

oda.Fill(dt);



GridView1.DataBind();



}



catch(Exception ex )

{



}

}

I want to display rows in ascending order in gridview after clicking on button. please help me, Here is the code.

protected void Button2_Click(object sender, EventArgs e)
{
try
{
DataTable dt = new DataTable();
Dbconn.Open();
string str = "select id,dte from test order by id asc";
oda = new OracleDataAdapter(str, Dbconn);
oda.Fill(dt);

GridView1.DataBind();

}

catch (Exception ex)
{

}
}

What I have tried:

protected void Button2_Click(object sender, EventArgs e)
{
try
{
DataTable dt = new DataTable();
Dbconn.Open();
string str = "select id,dte from test order by id asc";
oda = new OracleDataAdapter(str, Dbconn);
oda.Fill(dt);

GridView1.DataBind();

}

catch (Exception ex)
{

}
}

推荐答案

请参阅以下文章



如何在ASP.NET中的Gridview中执行排序 [ ^ ]





在.aspx页面中,您需要指定OnSorting事件,并需要将AllowSorting = true设置为GridView。然后你需要在OnSorting事件中指定的方法中添加排序逻辑
Please refer the following article

How to Perform Sorting in Gridview in ASP.NET[^]


In the.aspx page you need to specify the OnSorting event and need to set AllowSorting=true to the GridView. Then you need to add the sorting logic in the method specified in OnSorting event


你需要按照下面的方式设置GridView数据源属性;

You need to set the GridView datasource property as per below;
// Fill the datatable from your adapter
odaFill(dt);
// Set the grid data source
GridView1.DataSource = dt;
// bind the grid
GridView1.DataBind();





亲切的问候



Kind Regards


这篇关于我想在点击按钮后在gridview中按升序显示行。请帮我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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