Gridview和复选框问题 [英] Gridview and checkbox problem

查看:83
本文介绍了Gridview和复选框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有.aspx和aspx.cs文件。在.aspx我有asp:GridView。在aspx.cs文件中,我有一个方法getCheckedProduct,我得到检查值

  private   void  getCheckedProduct()
{
if (selected == string .Empty)
{
selected = Request.Form [ selectProductName];
}
其他 如果(已选择!= 字符串 .Empty&&& Request.Form [ selectProductName] != string .Empty)
{
selected = selected + + Request.Form [ selectProductName ]。
}
}





当我将GridView页面从1更改为2并从2更改为1时, if语句(&& Request.Form [selectProductName]!= string.Empty)) in getCheckedProduct()方法不检测tis ...在变量selected中添加,。为什么?

解决方案

在页面中放置一个静态字符串并在回发之前获取该值

然后在你的后再次调用此方法gridview pagination

 static string selected =; 
protected void Page_Load(object sender,EventArgs e)
{
if(!IsPostBack)
{
getCheckedProduct();
}
}





在分页时,只需调用所选字符串并将其与您的要求一起使用


Hi, i have .aspx and aspx.cs file. In .aspx i have asp:GridView. In aspx.cs file, i have a method getCheckedProduct, where i get checked values

private void getCheckedProduct()
{
   if (selected == string.Empty)
   {
      selected = Request.Form["selectProductName"];
   }
   else if (selected != string.Empty && Request.Form["selectProductName"] != string.Empty)
   {
      selected = selected + "," + Request.Form["selectProductName"];
   }
}



When i change the GridView page from 1 to 2 and back from 2 to 1, if statement ("&& Request.Form["selectProductName"] != string.Empty)") in getCheckedProduct() method does not detect tis... in the variable "selected" is added ",". Why?

解决方案

put a static string in your page and get that value before postback
Then no need to call this method again after your gridview pagination

static string selected = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getCheckedProduct();
        }
    } 



In pagination time just call the string selected and use it with your requirements


这篇关于Gridview和复选框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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