前台代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>物流系统</title>
<link rel="stylesheet" type="text/css" href="../Css/main.css" />
</head>
<body>
<form id="frm_Main" runat="server">
<ext
ageManager ID="pm_Main" AutoSizePanelID="pnl_Main" runat="server" />
<ext
anel ID="pnl_Main" runat="server" EnableBackgroundColor="true" BodyPadding="3px"
Height="" EnableLargeHeader="true" Title="客户管理" ShowBorder="False" ShowHeader="False"
Layout="Fit">
<Toolbars>
<ext:Toolbar ID="tlr_Btn" runat="server">
<Items>
<ext:Button ID="btn_Delete" Icon="DatabaseDelete" ConfirmText="确定要删除选中行记录及其该行相关所有记录么?" Text="删除" runat="server"
OnClick="btn_Delete_Click">
</ext:Button>
<ext:Button ID="btn_Search" Icon="DatabaseConnect" Text="筛选" runat="server">
</ext:Button>
</Items>
</ext:Toolbar>
</Toolbars>
<Items>
<ext:Grid ID="gr_Main" ShowHeader="False" runat="server" EnableCheckBoxSelect="true" AllowSorting="true" PageSize="20" ShowBorder="true" AllowPaging="true" EnableTextSelection="true" EnableRowNumber="True"
OnSort="Gr_Sort" IsDatabasePaging="true"
DataKeyNames="muId" AutoScroll="true" EnableRowDoubleClick="true">
<Columns>
。。。。
</Columns>
</ext:Grid>
</Items>
</ext
anel>
<ext:Window ID="win_Search" Title="详细筛选" Hidden="true" Icon="ApplicationFormMagnify" Target="Self"
runat="server" IsModal="true" CloseAction="HidePostBack" Width="600px" Height="332px">
<Items>
<ext
anel ID="pnl_Search" runat="server" Layout="Fit" ShowBorder="False" ShowHeader="false" Height="300px" EnableBackgroundColor="true">
<Items>
<ext:Form ID="sf_Search" BodyPadding="25px 15px" LabelWidth="100" AutoScroll="true" ShowBorder="false" ShowHeader="false" EnableBackgroundColor="true" runat="server">
<Rows>
<ext:FormRow ColumnWidths="50% 50%">
<Items>
<ext
ropDownList runat="server" ID="ddl_State" Label="状态"></ext
ropDownList>
</Rows>
</ext:Form>
</Items>
<Toolbars>
<ext:Toolbar ID="tbr_Search" Position="Bottom" runat="server">
<Items>
<ext:ToolbarFill ID="tf_sb" runat="server"></ext:ToolbarFill>
<ext:Button ID="btn_XSearch" Text="检索" ValidateForms="sf_Search" runat="server" Icon="TextRuler">
</ext:Button>
</Items>
</ext:Toolbar>
</Toolbars>
</ext
anel>
</Items>
</ext:Window>
</form>
</body>
</html>
后台代码:
public partial class UserMng_Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
protected void btn_Delete_Click(object sender, EventArgs e)
{
}
protected void btn_Search_Click(object sender, EventArgs e)
{
ddl_State.Items.Clear();
ddl_State.Items.Add("锁定", "0");
ddl_UserType.Items.Clear();
ddl_UserType.Items.Add("内部用户", "1");
win_Search.Hidden = false;
}
protected void Gr_PageIndexChange(object sender, GridPageEventArgs e)
{
gr_Main.PageIndex = e.NewPageIndex;
BindGrid();
}
protected void Gr_Sort(object sender, GridSortEventArgs e)
{
BindGridWithSort(string.Empty, e.SortField, e.SortDirection);
}
protected void win_Edit_Close(object sender, WindowCloseEventArgs e)
{
Session["muId"] = null;
}
private void BindGrid()
{
BindGridWithSort(string.Empty, string.Empty, string.Empty);
}
private void BindGridWithSort(string strWhere, string sortField, string sortDirection)
{
int startIndex = gr_Main.PageIndex * gr_Main.PageSize + 1;
int endIndex = startIndex + gr_Main.PageSize - 1;
UserManager bll = new UserManager();
gr_Main.RecordCount = bll.GetAllUserCount();
DataView view1 = bll.GetListByPage(strWhere, startIndex, endIndex).Tables[0].DefaultView;
view1.Sort = String.Format("{0} {1}", sortField, sortDirection);
gr_Main.DataSource = view1;
gr_Main.DataBind();
}
protected void btn_Modify_Click(object sender, EventArgs e)
{
int[] selectedIndexArr = gr_Main.SelectedRowIndexArray;
if (selectedIndexArr.Length!=1)
{
Alert.Show("请选中一行修改!");
return;
}
string dataKey = gr_Main.DataKeys[selectedIndexArr[0]][0].ToString();
Session["muId"] = dataKey;
win_Edit.IFrameUrl = "Edit.aspx";
win_Edit.Title = "用户信息编辑";
win_Edit.Hidden = false;
}
protected void btn_Refresh_Click(object sender, EventArgs e)
{
BindGrid();
}
protected void btn_Return_Click(object sender, EventArgs e)
{
win_Search.Hidden = true;
}
protected void btn_XSearch_Click(object sender, EventArgs e)
{
string sqlWhere = " 1=1";
if (!string.IsNullOrEmpty(ddl_State.SelectedValue))
{
sqlWhere += string.Format(" and muStatus='{0}'", ddl_State.SelectedText);
}
BindGridWithSort(sqlWhere, string.Empty, string.Empty);
win_Search.Hidden = true;
}
}
作者: sanshi 时间: 2014-3-17 22:48
用空项目重现问题:http://fineui.com/bbs/forum.php?mod=viewthread&tid=2123
作者: dwc 时间: 2014-3-18 09:19
已经解决,谢谢你。
是我后台代码问题:
GridView中的RecordCount值和DataSource中的记录数不一致。
private void BindGridWithSort(string strWhere, string sortField, string sortDirection)
{
int startIndex = gr_Main.PageIndex * gr_Main.PageSize + 1;
int endIndex = startIndex + gr_Main.PageSize - 1;
UserManager bll = new UserManager();
gr_Main.RecordCount = bll.GetAllUserCount(); //此行与下行代码的数据条数不一致,是问题根结
DataView view1 = bll.GetListByPage(strWhere, startIndex, endIndex).Tables[0].DefaultView;
view1.Sort = String.Format("{0} {1}", sortField, sortDirection);
gr_Main.DataSource = view1;
gr_Main.DataBind();
}
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/) |
Powered by Discuz! X3.4 |