当DataGrid同时具有分页和排序功能时应注意在重新绑定数据源时,MyDataGrid.CurrentPageIndex=0;
下面给实现以上功能的原码,也就不多缀了aspx中包含有DataGrid和控制其数据源变化的dropdownlist
DataGrid代码
<asp:datagrid id="MyDataGrid" runat="server" BorderColor="#CCCCCC" Font-Size="100%" HorizontalAlign="Center"
AutoGenerateColumns="False" OnDeleteCommand="MyDataGrid_Delete" OnSortCommand="Sort_Grid" OnPageIndexChanged="MyDataGrid_PageIndexChanged"
DataKeyField="ACC_NO" PagerStyle-Position="Bottom" PagerStyle-HorizontalAlign="Center" PagerStyle-Mode="NextPrev"
PageSize="10" AllowSorting="True" AllowPaging="True" CellPadding="4" Width="100%">
<AlternatingItemStyle BackColor="#E9E9E6"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" Wrap="False" ForeColor="White" BackColor="#999999"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="口" CommandName="Delete"></asp:ButtonColumn>
<asp:BoundColumn DataField="NO" SortExpression="NO" ReadOnly="True" HeaderText="序号"></asp:BoundColumn>
<asp:BoundColumn DataField="ID" SortExpression="ID" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="NAME" SortExpression="NAME" HeaderText="名称"></asp:BoundColumn>
<asp:BoundColumn DataField="C_NAME" SortExpression="C_NAME" HeaderText="各科名称"></asp:BoundColumn>
<asp:BoundColumn DataField="FLG" SortExpression="FLG" HeaderText="项目"></asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="下10件" PrevPageText="返回" HorizontalAlign="Center"></PagerStyle>
</asp:datagrid>
dropdownlist代码
<asp:dropdownlist id="ddlWk" Runat="server" AutoPostBack="True" Enabled="False">
<asp:ListItem Value="0">东京</asp:ListItem>
<asp:ListItem Value="3">九州</asp:ListItem>
<asp:ListItem Value="8">北海道</asp:ListItem>
<asp:ListItem Value="9">四国</asp:ListItem>
</asp:dropdownlist>
aspx.cs文件代码核心如下:
private void Page_Load(object sender, System.EventArgs e)
"WP"] ="0";
ddlWk_getS();
BindGrid();
"WP"].ToString())
"0":ddlWk.SelectedIndex=0;
break;
case "3":ddlWk.SelectedIndex=1;
break;
case "8":ddlWk.SelectedIndex=2;
break;
case "9":ddlWk.SelectedIndex=3;
break;
default:ddlWk.SelectedIndex=0;
break;
"vCO"].DefaultView;
MyDataGrid.DataBind();
//COUNT.Text=MyDataGrid.Columns.Count.ToString();
"system.web/database"))["strConn"];
using (SqlConnection conn = new SqlConnection(strConn))
"sp_C",conn);
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.Add("@place",SqlDbType.VarChar,2);
cmd.Parameters["@place"].Value=Session["WP"].ToString();
conn.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand=cmd;
DataSet ds=new DataSet();
da.Fill(ds,"vCO");
Count.Text="ヒット:"+ds.Tables["vCO"].Rows.Count.ToString()+"件";
return ds;
"sender"></param>
/// <param name="E"></param>
protected void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs E)
"sender"></param>
/// <param name="e"></param>
protected void MyDataGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
"sender"></param>
/// <param name="e"></param>
protected void Sort_Grid(object sender, DataGridSortCommandEventArgs e)
"vCO"]);
dv.Sort= e.SortExpression.ToString();
MyDataGrid.DataSource=dv;
MyDataGrid.DataBind();
"WP"]=ddlWk.SelectedValue;
MyDataGrid.CurrentPageIndex=0;//没有这一句,当该页码超出其他数据源的范围时会出错
BindGrid();
Response.Write( "<script language='javascript'>parent.menuframe.location.reload();</script>");
}
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 上山安娜.1986-上山安娜【EMI百代】【WAV+CUE】
- 张真.1993-失恋十四行【上华】【WAV+CUE】
- 钟明秋《爱有天意HQCD》[低速原抓WAV+CUE]
- 孙云岗唢呐《金声玉振[HIFI珍藏版]》[低速原抓WAV+CUE]
- 谭艳精讯TEST-CD试音39号》2CD[DTS-WAV]
- 姚璎格《发烧女中音》DSD版[低速原抓WAV+CUE][1G]
- 张玮伽《微风细雨DSD》发烧大碟[WAV+CUE][1.1G]
- 群星《2024好听新歌14》十倍音质 U盘音乐 [WAV分轨][966M]
- s14全球总决赛T1战队队员都有谁 LOLs14全球总决赛T1战队介绍
- 英雄联盟faker身价有10亿吗 英雄联盟faker身价介绍一览
- faker大魔王称号怎么来的 faker大魔王称号来源介绍
- PS5 Pro上的蒂法更美了!博主盛赞新机1000%值得购买
- 腾讯互娱再离职一员大将!或因供应商贪腐
- Ayaneo3游戏掌机预热:旗舰定位、造型圆润自带底键
- 动力火车.1999-背叛情歌【上华】【WAV+CUE】