在线等,急:gridview 中编辑和翻页的问题!!!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在线等,急:gridview 中编辑和翻页的问题!!!相关的知识,希望对你有一定的参考价值。

我的公用连接数据库的类有这几个方法:
protected void Open()

XXXXXXXX

public void Close()

XXXXXXX

public OdbcDataReader GetDataReader(String SqlString)

Open();
OdbcCommand cmd = new OdbcCommand(SqlString, Connection);
return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

public DataSet GetDataSet(String SqlString)

DataSet dataset = new DataSet();
Open();
try

OdbcDataAdapter adapter = new OdbcDataAdapter(SqlString, Connection);
adapter.Fill(dataset);

catch (Exception e)

throw new Exception(e.Message);


finally

Close();

return dataset;


现在我在页面中要实现 gridview的反页和编辑功能
该怎么办呢`高手来指点一定要写详细点 ` 我基础很差`谢谢.

<asp:Button ID="Button1" runat="server" Text="查询" OnClick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="true" AllowSorting="True" AutoGenerateColumns="False" OnSorting="GridView1_Sorting" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" Width="100%" Font-Size="10pt">
<Columns>
<asp:BoundField DataField="sz_branch_no" HeaderText="机构号" SortExpression="sz_branch_no"/>
<asp:BoundField DataField="sz_code" HeaderText="工号" SortExpression="sz_code"/>
<asp:BoundField DataField="name" HeaderText="姓名" SortExpression="name" />
<asp:BoundField DataField="sex" HeaderText="性别" SortExpression="sex" />
<asp:BoundField DataField="id_no" HeaderText="身份证号码" SortExpression="id_no"/>
</Columns>
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>

private void DataBinds()

PagedDataSource pds = new PagedDataSource();
pds.DataSource = BookManager.GetNewBooks();
pds.AllowPaging = true;
pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
this.AspNetPager1.RecordCount = 20;//数据总数,我这里直接写20,应该是你数据count()值

pds.PageSize = this.AspNetPager1.PageSize;

this.GridView.DataSource = pds;
this.GridView.DataBind();
参考技术A 麻烦把错误贴出来下! 参考技术B 翻页的话,有几种方法,最简单的是用GridView自带的翻页功能,在就是还可以你自己写一些翻页方法,在页面调用给GridView,我用的是一个叫aspnetpager的翻页控件,你可以在网上搜搜,用法跟其他控件一样,直接拖到页面上就行了,然后就是后台代码绑定,给你一个我以前绑定的方法看看:
private void DataBinds()

PagedDataSource pds = new PagedDataSource();
pds.DataSource = BookManager.GetNewBooks();
pds.AllowPaging = true;
pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
this.AspNetPager1.RecordCount = 20;//数据总数,我这里直接写20,应该是你数据count()值

pds.PageSize = this.AspNetPager1.PageSize;

this.GridView.DataSource = pds;
this.GridView.DataBind();


至于你说的编辑,同样你也可以用GridView自带的更新功能,不过不太好,至于手动的话,最好把你要实现的功能说下

ASP.NET GridView代码实现编辑,删除功能

参考技术A 解决方法有两种:
1.你调试一下gridview2_rowupdating中的gridview2.rows[e.rowindex].cells[x].controls[0]的实际值为多少,根据实际情况,对应到你的sql语句中。x为0,1,2,3。
2.用repeater,datalist的替换gridview,然后,通过在相应的列中添加button按钮做为删除、更新等用户接口。用command事件处理实际的删除、更新等操作。
ps:不建议经常使用gridview这种控件,不利于你了解实际代码的运行过程。

以上是关于在线等,急:gridview 中编辑和翻页的问题!!!的主要内容,如果未能解决你的问题,请参考以下文章

分页的Gridview要导出excel怎么导出。如果有2页信息。在导出的excel中可以看到全部的信息怎么做?急急急

Python网络爬虫_爬取Ajax动态加载和翻页时url不变的网页

如果 Linux里的 VI编辑器中 按啥键 让命令行前面出现数字 在线等 急急急

app测试与web测试的区别

高分求助:WPF datagird控件数据的增删改查。急

asp.net中GridView怎样进行分页,编辑,删除操作