在webgrid中单击第二页时,过滤后的数据会丢失 [英] pagination on filtered data getting lost on when clicked on second page in webgrid

查看:98
本文介绍了在webgrid中单击第二页时,过滤后的数据会丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击webgrid第二页时过滤后的数据分页



我的索引视图-----

< br $>


@ {

布局= null;

}



@ {



var grdLocation = new WebGrid(来源:Model,rowsPerPage:3,selectionFieldName:selectedRow,canSort:false,fieldNamePrefix:DateTimeOffset );

grdLocation.Pager(WebGridPagerModes.All);







}

<!DOCTYPE html>

< html>

< head>

< ; title> Location Master< / title>

< link href =../../ Css / CommonStyle.css =stylesheettype =text / css/>

< script src =../../ Js / jquery-1.8.0.min.jstype =text / javascript>< / script>

< style type =text / css>

。隐藏

{

display:none;

}

.Buttonscs

{

border-top-style:none;

border -bottom-style:none;

border-left-style:none;

border-right-style:none;

颜色:白色;

字体大小:0px;

}

< / style>

< script type = text / javascriptlanguage =javascript>



$(document).ready(function(){

$(' #btSearch')。show();

$('#btnCreate')。show();

$('#btnExport')。hide();

$('#btnDelete')。show();



});

< / script> ;

< / head>

@using(Html.BeginForm(Index,Location,FormMethod.Post))

{

< body>



@ *< form id =Form1action =&g t; * @





位置大师








< td class =bigtd>国家/地区姓名

位置名称

< input id =txtlocationnametype =textname =txtlocationnameclass =bigtextboxvalue ='@ Session [txtlocationname]'/ gt ;

位置代码

< input id =txtlocationcode type =textname =txtlocationcodeclass =bigtextboxvalue ='@ Session [txtlocationcode]'/>

< input id =txtcountrynametype =textname =txtcountrynameclass =bigtextbox/>

城市名称

< input id =txtdestinationnametype = textname =txtdestinationnameclass =bigtextboxvalue ='@ Session [txtdestinationname]'/>

@ Html.Partial(_ UserButtons,型号)






















@if(@Model!= null)

{

@ grdLocation.GetHtml(

tableStyle:WebGrid,

headerStyle:webgridheader,

alternatingRowStyle:webgridaltrowstyle,

selectedRowStyle:select,

rowStyle:webgridrowstyle,

footerStyle:webgridfooter,



firstText:First,

lastText:Last,

nextText:Next,

模式:WebGridPagerModes.All,

previousText:Previous,

列:grdLocation.Columns(

grdLocation。列(location_code,位置代码,样式:webgridwrap),

grdLocation.Column(location_name,Location,样式:webgridwrap),

grdLocation.Column(country_name,Country,style:webgri dwrap),

grdLocation.Column(state_name,State,style:webgridwrap),

grdLocation.Column(zone,Zone ,style:webgridwrap),

grdLocation.Column(city_name,City,style:webgridwrap),

grdLocation.Column(location_address) ,地址,样式:webgridwrap),

grdLocation.Column(location_pin_code,Pin Code,样式:webgridwrap),

grdLocation。列(location_telephone_no,电话,样式:webgridwrap),

grdLocation.Column(location_fax_no,传真否,样式:webgridwrap),

grdLocation.Column(location_email_id,电子邮件ID,样式:webgridwrap),

grdLocation.Column(report_name,报告城市,样式:webgridwrap) ,

grdLocation.Column(vendor_report_name,供应商报告城市,样式:webgridwrap ),

grdLocation.Column(location_is_active,活动状态,样式:webgridwrap),

grdLocation.Column(created_by,Created By ,style:webgridwrap),

grdLocation.Column(created_on,Created On,style:webgridwrap),

grdLocation.Column(updated_by ,更新者,样式:webgridwrap),

grdLocation.Column(updated_on,更新时间,样式:webgridwrap)





}



@ *< / form> * @

< / body>

}

< / html>







型号是-----











公共类别LocationModel

{

public int location_id {get;组; }

public string location_code {get;组; }

public string location_name {get;组; }

public int location_country_id {get;组; }

public int location_destination_id {get;组; }

public string location_destination {get;组; }

public string location_address {get;组; }

public int location_pin_code {get;组; }

public string location_telephone_no {get;组; }

public string location_fax_no {get;组; }

public string location_email_id {get;组; }

public bool location_is_active {get;组; }

public string T2 {get;组; }

public string acc_code {get;组; } $ / $
public int reporting_city_id {get;组; } $ / $
public int vendor_reporting_city_id {get;组; }

public string city_name {get;组; } $ / $
public string vendor_report_name {get;组; }

public string report_name {get;组; }

public string zone {get;组; } $ / $
public int state_id {get;组; } $ / $
public string state_name {get;组; }

public string country_name {get;组; }

public double rr_amt {get;组; } $ / $
public int created_by_id {get;组; }

public string created_by {get;组; }

public string created_on {get;组; } $ / $
public int updated_by_id {get;组; }

public string updated_by {get;组; }

public string updated_on {get;组; }



public List< locationmodel> Get_LocationData(LocationModel lm)

{

List< locationmodel> location = new List< locationmodel>();

SqlCommand cmd = new SqlCommand();

SqlDataAdapter adp = new SqlDataAdapter(cmd);

DataTable dtLocation = new DataTable();

try

{

adp.SelectCommand.CommandType = CommandType.StoredProcedure;

cmd.CommandText =usp_get_location_master;



cmd.Parameters.AddWithValue(@ p_location_name,lm.location_name);

cmd.Parameters.AddWithValue(@ p_location_code,lm.location_code);

cmd.Parameters.AddWithValue(@ p_location_destination_name,lm.location_destination);

cmd .Parameters.AddWithValue(@ p_location_country_name,lm.country_name);



DataBaseHandler objhandler = new DataBaseHandler();

objhandler.ExecuteProc edure(cmd);

adp.Fill(dtLocation);



var lstlocation =(来自dr in dtLocation.AsEnumerable()

选择新的LocationModel

{

location_destination_id = Convert.ToInt32(dr [location_destination_id]。ToString()),

location_country_id = Convert.ToInt32(dr [location_country_id]。ToString()),

location_id = Convert.ToInt32(dr [location_id]。ToString()),

location_code = dr [location_code]。ToString(),

location_name = dr [location_name]。ToString(),

state_name = dr [ state_name]。ToString(),

zone = dr [zon e]。ToString(),

location_address = dr [location_address]。ToString(),

location_pin_code = Convert.ToInt32(dr [location_pin_code]。 ToString()),

location_telephone_no = dr [location_telephone_no]。ToString(),

location_fax_no = dr [location_fax_no]。ToString(),

location_email_id = dr [location_email_id]。ToString(),

vendor_report_name = dr [vendor_report_name]。ToString(),

report_name = dr [Report_name]。ToString(),

location_is_active = Convert.ToBoolean(dr [location_is_active]。ToString()),

country_name = dr [country_name ] .ToString(),

city_name = dr [city_name]。ToString(),

created_by = dr [created_by]。ToString(),

created_on = dr [created_on] .ToString(),

updated_by = dr [updated_by]。ToString(),

updated_on = dr [updated_on]。ToString()

})。ToList();



返回lstlocation;

}

catch(异常) ex)

{

抛出新的例外(ex.Message);

}

终于

{

dtLocation.Dispose();

adp.Dispose();

cmd.Dispose();

}

}

}

}









Contorllrer是 - -





公共类LocationController:Controller

{

LocationModel lm;

[HttpGet]

公共ActionResult索引()

{

lm = new LocationModel();

lm.location_name = Session [txtlocationname] == null? :Session [txtlocationname]。ToString();

lm.location_code = Session [txtlocationcode] == null? :Session [txtlocationcode]。ToString();

lm.country_name = Session [txtcountryname] == null? :Session [txtcountryname]。ToString();

lm.location_destination = Session [txtdestinationname] == null? :Session [txtdestinationname]。ToString();



var GridData = lm.Get_LocationData(lm);

return View (GridData);

}

[HttpPost]

公共ActionResult索引(字符串命令,FormCollection frm)

{

Session [txtlocationname] = frm [txtlocationname];

Session [txtlocationcode] = frm [txtlocationcode];

Session [txtcountryname] = frm [txtcountryname];

Session [txtdestinationname] = frm [txtdestinationname];

switch(命令)

{

案例搜索:

lm = new LocationModel();

lm.location_name = frm [txtlocationname] == null? :frm [txtlocationname];

lm.location_code = frm [txtlocationcode] == null? :frm [txtlocationcode];

lm.country_name = frm [txtcountryname] == null? :frm [txtcountryname];

lm.location_destination = frm [txtdestinationname] == null? :frm [txtdestinationname];

var GridData = lm.Get_LocationData(lm);

返回View(GridData);

休息;



案例创建:

返回重定向(Url.Action(创建,位置));

休息;



案例导出:



返回重定向(Url。动作(创建,位置));

返回重定向(Url.Action(创建,位置));

break;

默认:

返回查看(索引);

休息;

}

}







在gridview页面上更改所有文本框清除数据...我使用seession来维护它,但我想要一些其他方式....请帮助..谢谢我n advance

解决方案

(document).ready(function(){


('#btnSearch') .show();


('#btnCreate')。show();


pagination on filtered data getting lost on when clicked on second page in webgrid

My Index view -----


@{
Layout = null;
}

@{

var grdLocation = new WebGrid(source: Model, rowsPerPage: 3, selectionFieldName: "selectedRow", canSort: false,fieldNamePrefix:"DateTimeOffset");
grdLocation.Pager(WebGridPagerModes.All);



}
<!DOCTYPE html>
<html>
<head>
<title>Location Master</title>
<link href="../../Css/CommonStyle.css" rel="stylesheet" type="text/css" />
<script src="../../Js/jquery-1.8.0.min.js" type="text/javascript"></script>
<style type="text/css">
.Hidden
{
display: none;
}
.Buttonscs
{
border-top-style: none;
border-bottom-style: none;
border-left-style: none;
border-right-style: none;
color: White;
font-size: 0px;
}
</style>
<script type="text/javascript" language="javascript">

$(document).ready(function () {
$('#btnSearch').show();
$('#btnCreate').show();
$('#btnExport').hide();
$('#btnDelete').show();

});
</script>
</head>
@using (Html.BeginForm("Index", "Location", FormMethod.Post))
{
<body>

@*<form id="Form1" action="">*@


Location Master




Location Name
<input id="txtlocationname" type="text" name="txtlocationname" class="bigtextbox" value='@Session["txtlocationname"]' />
Location Code
<input id="txtlocationcode" type="text" name="txtlocationcode" class="bigtextbox" value='@Session["txtlocationcode"]' />
Country Name
<input id="txtcountryname" type="text" name="txtcountryname" class="bigtextbox" />
City Name
<input id="txtdestinationname" type="text" name="txtdestinationname" class="bigtextbox" value='@Session["txtdestinationname"]' />
@Html.Partial("_UserButtons",Model)











@if (@Model != null)
{
@grdLocation.GetHtml(
tableStyle: "WebGrid",
headerStyle: "webgridheader",
alternatingRowStyle: "webgridaltrowstyle",
selectedRowStyle: "select",
rowStyle: "webgridrowstyle",
footerStyle: "webgridfooter",

firstText: "First",
lastText: "Last",
nextText: "Next",
mode: WebGridPagerModes.All,
previousText: "Previous",
columns: grdLocation.Columns(
grdLocation.Column("location_code", "Location Code", style: "webgridwrap"),
grdLocation.Column("location_name", "Location", style: "webgridwrap"),
grdLocation.Column("country_name", "Country", style: "webgridwrap"),
grdLocation.Column("state_name", "State", style: "webgridwrap"),
grdLocation.Column("zone", "Zone", style: "webgridwrap"),
grdLocation.Column("city_name", "City", style: "webgridwrap"),
grdLocation.Column("location_address", "Address", style: "webgridwrap"),
grdLocation.Column("location_pin_code", "Pin Code", style: "webgridwrap"),
grdLocation.Column("location_telephone_no", "Telephone", style: "webgridwrap"),
grdLocation.Column("location_fax_no", "Fax No", style: "webgridwrap"),
grdLocation.Column("location_email_id", "Email ID", style: "webgridwrap"),
grdLocation.Column("report_name", "Reporting City", style: "webgridwrap"),
grdLocation.Column("vendor_report_name", "Vendor Reporting City", style: "webgridwrap"),
grdLocation.Column("location_is_active", "Active Status", style: "webgridwrap"),
grdLocation.Column("created_by", "Created By", style: "webgridwrap"),
grdLocation.Column("created_on", "Created On", style: "webgridwrap"),
grdLocation.Column("updated_by", "Updated By", style: "webgridwrap"),
grdLocation.Column("updated_on", "Updated On", style: "webgridwrap")
)
)
}


@* </form>*@
</body>
}
</html>



Models is-----





public class LocationModel
{
public int location_id { get; set; }
public string location_code { get; set; }
public string location_name { get; set; }
public int location_country_id { get; set; }
public int location_destination_id { get; set; }
public string location_destination { get; set; }
public string location_address { get; set; }
public int location_pin_code { get; set; }
public string location_telephone_no { get; set; }
public string location_fax_no { get; set; }
public string location_email_id { get; set; }
public bool location_is_active { get; set; }
public string T2 { get; set; }
public string acc_code { get; set; }
public int reporting_city_id { get; set; }
public int vendor_reporting_city_id { get; set; }
public string city_name { get; set; }
public string vendor_report_name { get; set; }
public string report_name { get; set; }
public string zone { get; set; }
public int state_id { get; set; }
public string state_name { get; set; }
public string country_name { get; set; }
public double rr_amt { get; set; }
public int created_by_id { get; set; }
public string created_by { get; set; }
public string created_on { get; set; }
public int updated_by_id { get; set; }
public string updated_by { get; set; }
public string updated_on { get; set; }

public List<locationmodel> Get_LocationData(LocationModel lm)
{
List<locationmodel> location = new List<locationmodel>();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dtLocation = new DataTable();
try
{
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_get_location_master";

cmd.Parameters.AddWithValue("@p_location_name", lm.location_name);
cmd.Parameters.AddWithValue("@p_location_code", lm.location_code);
cmd.Parameters.AddWithValue("@p_location_destination_name", lm.location_destination);
cmd.Parameters.AddWithValue("@p_location_country_name", lm.country_name);

DataBaseHandler objhandler = new DataBaseHandler();
objhandler.ExecuteProcedure(cmd);
adp.Fill(dtLocation);

var lstlocation = (from dr in dtLocation.AsEnumerable()
select new LocationModel
{
location_destination_id = Convert.ToInt32(dr["location_destination_id"].ToString()),
location_country_id = Convert.ToInt32(dr["location_country_id"].ToString()),
location_id = Convert.ToInt32(dr["location_id"].ToString()),
location_code = dr["location_code"].ToString(),
location_name = dr["location_name"].ToString(),
state_name = dr["state_name"].ToString(),
zone = dr["zone"].ToString(),
location_address = dr["location_address"].ToString(),
location_pin_code = Convert.ToInt32(dr["location_pin_code"].ToString()),
location_telephone_no = dr["location_telephone_no"].ToString(),
location_fax_no = dr["location_fax_no"].ToString(),
location_email_id = dr["location_email_id"].ToString(),
vendor_report_name = dr["vendor_report_name"].ToString(),
report_name = dr["Report_name"].ToString(),
location_is_active = Convert.ToBoolean(dr["location_is_active"].ToString()),
country_name = dr["country_name"].ToString(),
city_name = dr["city_name"].ToString(),
created_by = dr["created_by"].ToString(),
created_on = dr["created_on"].ToString(),
updated_by = dr["updated_by"].ToString(),
updated_on = dr["updated_on"].ToString()
}).ToList();

return lstlocation;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
dtLocation.Dispose();
adp.Dispose();
cmd.Dispose();
}
}
}
}




Contorllrer is---


public class LocationController : Controller
{
LocationModel lm;
[HttpGet]
public ActionResult Index()
{
lm = new LocationModel();
lm.location_name = Session["txtlocationname"] == null ? "" : Session["txtlocationname"].ToString();
lm.location_code = Session["txtlocationcode"] == null ? "" : Session["txtlocationcode"].ToString();
lm.country_name = Session["txtcountryname"] == null ? "" : Session["txtcountryname"].ToString();
lm.location_destination = Session["txtdestinationname"] == null ? "" : Session["txtdestinationname"].ToString();

var GridData = lm.Get_LocationData(lm);
return View(GridData);
}
[HttpPost]
public ActionResult Index(string Command, FormCollection frm)
{
Session["txtlocationname"] = frm["txtlocationname"];
Session["txtlocationcode"] = frm["txtlocationcode"];
Session["txtcountryname"] = frm["txtcountryname"];
Session["txtdestinationname"] = frm["txtdestinationname"];
switch (Command)
{
case "Search":
lm = new LocationModel();
lm.location_name = frm["txtlocationname"] == null ? "" : frm["txtlocationname"];
lm.location_code = frm["txtlocationcode"] == null ? "" : frm["txtlocationcode"];
lm.country_name = frm["txtcountryname"] == null ? "" : frm["txtcountryname"];
lm.location_destination = frm["txtdestinationname"] == null ? "" : frm["txtdestinationname"];
var GridData = lm.Get_LocationData(lm);
return View(GridData);
break;

case "Create":
return Redirect(Url.Action("Create", "Location"));
break;

case "Export":

return Redirect(Url.Action("Create", "Location"));
return Redirect(Url.Action("Create", "Location"));
break;
default:
return View("Index");
break;
}
}



On gridview page changing All my textbox clears data...i used seession to maintain it but i want some other way....please help..thanx in advance

解决方案

(document).ready(function () {


('#btnSearch').show();


('#btnCreate').show();


这篇关于在webgrid中单击第二页时,过滤后的数据会丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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