首页 新闻 会员 周边 捐助

gridview使用linkbutton进行修改数据,分页成功但是点击其他页的修改时总是自动跳转到第一页

1
悬赏园豆:30 [已解决问题] 解决于 2013-03-14 18:31
前台
后台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using baseclass;
using System.Data;
using System.Collections;

public partial class admin_Gray_list : System.Web.UI.Page
{
    const int iic_Row = 10;
    protected void Page_Load(object sender, EventArgs e)
    {
            vf_findblaclist(1);
    }


    protected void vf_findblaclist(int al_index)
    {
        string ls_sql;
        //if (Session["ws_Uname"] == null)
        //    Response.Redirect("login.aspx");
        ls_sql = @"select mobile,username,lost_reason,inputname,insdate,id  from mobileSendGrayList order by id desc";
        n_findby_dw lnv_find = new n_findby_dw();
        lnv_find.of_setSQL(ls_sql);
        lnv_find.of_SetTop(iic_Row);

        if (txt_phone.Value.Trim() != "")
        {

            lnv_find.of_add_ons("mobile", "mobile like '" + txt_phone.Value.Trim() + "%'");

        }

        if (txt_name.Value.Trim() != "")
        {

            lnv_find.of_add_ons("username", "username like '%" + txt_name.Value.Trim() + "%'");

        }
        string ls_where;

        ls_where = lnv_find.of_GetAllwhere();

        string ls_Inwhere = "";
        int ll_RowCount;
        int li_pagesize = iic_Row;
        ll_RowCount = MyAspPage.Of_GetPageWhere(ls_sql, "id", ls_where, li_pagesize, al_index, ref ls_Inwhere);
        if (al_index == 1)
        {
            AspNetPager1.RecordCount = ll_RowCount;
            AspNetPager1.PageSize = li_pagesize;
        }
        AspNetPager1.CurrentPageIndex = al_index;

        if (ls_Inwhere.Trim().Length > 0)
        {

            short x = lnv_find.of_add_ons("id", "id in (" + ls_Inwhere + ")");
        }
        else  //没有记录 ,则不要显示任何记录
        {
            lnv_find.of_add_ons("wj_id", "0=1");
        }
        ls_sql = lnv_find.of_GetSQLselect();
        DataTable dt = SqlHelper.ExecuteDataTable(ls_sql);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        
       vf_findblaclist(AspNetPager1.CurrentPageIndex);
    }
    protected void btn_serch_Click(object sender, EventArgs e)
    {
        vf_findblaclist(1);
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton LinkButton1 = (LinkButton)e.Row.FindControl("update");
            LinkButton1.CommandArgument = e.Row.RowIndex.ToString();
            LinkButton save = (LinkButton)e.Row.FindControl("LinkButton1");
            save.CommandArgument = e.Row.RowIndex.ToString();
        }

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      
        if (e.CommandName == "xiugai")
        {
            int s = Convert.ToInt32(e.CommandArgument);

            string sadas = (GridView1.Rows[s].FindControl("reason") as Label).Text;
            Control _displayControl = GridView1.Rows[s].FindControl("reason") as Label;
            _displayControl.Visible = false;
            Control lab = GridView1.Rows[s].FindControl("dropreason") as  DropDownList;
            lab.Visible = true;
            Control update = GridView1.Rows[s].FindControl("update") as LinkButton;
            update.Visible = false;
            Control link = GridView1.Rows[s].FindControl("LinkButton1") as LinkButton;
            link.Visible = true;
            LinkButton ss = GridView1.Rows[s].FindControl("update") as LinkButton;
            ss.Attributes.Add("CommandName", "javascript:return false;");
        }
        if (e.CommandName == "save")
        {
            int s = Convert.ToInt32(e.CommandArgument);
            string value = (GridView1.Rows[s].FindControl("dropreason") as DropDownList).Text.Trim();
            string id = (GridView1.Rows[s].FindControl("id") as Label).Text.Trim();
            string sql = "update mobileSendGrayList set lost_reason='" + value + "' where id='" + id + "'";
            SqlHelper.ExecuteNonQuery(sql);
            vf_findblaclist(1);
        }
    }
}

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Gray_xg.aspx.cs" Inherits="admin_Gray_list"   EnableViewState="false" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>手机定位管理-灰名单管理</title>
<link href="css/t_mode.css" rel="stylesheet" type="text/css" />
<%--<script type="text/javascript">
<!--
    function MM_popupMsg(msg) { //v1.0
        alert(msg);
    }
//-->

</script>--%>
<%--<style type="text/css">
.STYLE1 {color: #FF6600}
</style>--%>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <asp:ScriptManager ID="ScriptManager1" runat="server" />
    </div>
    
    <div class="con">
  <div class="mainCon">
<div class="rCon">
<div class="rl_01">
  <h4 class="md_title"><img src="images/gray_md.gif" width="24" height="24" align="absmiddle" />灰名单管理</h4>
<%--  <span class="md_zs">灰名单记录定位失败的手机号码和定位失败的原因</span></div>--%>
<div class="rl_03">
  <ul>
<table width="100%" border="0" cellspacing="1" bgcolor="#cce0f5">
  <tr>
    <td width="17%" height="32" align="right" bgcolor="#e5ffff">被定位手机号码:</td>
    <td width="18%" height="32" bgcolor="#e5ffff"><span class="con_kuang">
   <input name="txt_phone" type="text" class="wbk_02" id="txt_phone" size="18"  runat="server"/>
    </span></td>
    <td width="18%" align="right" bgcolor="#e5ffff">手机主人: </td>
    <td height="32" align="left" bgcolor="#e5ffff"><span class="con_kuang">
    <input name="txt_name" type="text" class="wbk_02" id="txt_name" size="18" runat="server" />
    </span><span style="padding-left:15px;"><a href="#"></a><a href="#">
    <asp:Button ID="btn_serch" runat="server" Text="查询" class="btn_next" 
            onclick="btn_serch_Click"  />
    </a></span></td>
    </tr>
</table>
  <p class="clear"></p>
  
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
              <ContentTemplate>
                    <asp:GridView ID="GridView1" runat="server"  Width="768px"  
                        AutoGenerateColumns="False" 
                        onrowcreated="GridView1_RowCreated" onrowcommand="GridView1_RowCommand" >
                      <Columns>
                         <asp:TemplateField>
                    <HeaderTemplate>
                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#cce0f5">
                <tr>
                  <td width="20%" height="25" align="center" bgcolor="#ebf5f5"><strong>被定位手机号码</strong></td>
                  <td width="20%" align="center" bgcolor="#ebf5f5"><strong>手机主人</strong><strong></strong></td>
                  <td width="50%" align="center" bgcolor="#ebf5f5"><strong class="shixiao">确认失败原因</strong><strong class="shixiao"></strong></td>
                  <td width="5%" align="center" bgcolor="#ebf5f5"><strong>修改</strong></td>
                  <td width="10%" align="center" bgcolor="#ebf5f5"><strong>详细</strong></td>
                </tr>
                </table>
                    </HeaderTemplate>
                    <ItemTemplate>
                <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#cce0f5">
                <tr>
                  <td height="25" align="center" width="20%" bgcolor="#FFFFFF"><%# Eval("mobile")%></td>
                  <td height="25" align="center" width="20%" bgcolor="#FFFFFF"><%# Eval("username ")%></td>
                  <td height="25" align="center" width="50%" bgcolor="#FFFFFF">
                  <asp:Label ID="reason" runat="server" Text=' <%# Eval("lost_reason") %>'></asp:Label>
                  <asp:DropDownList ID="dropreason" runat="server" Visible="false" AutoPostBack="false">
                            <asp:ListItem>手机已关机</asp:ListItem>
                            <asp:ListItem>手机号码已停机</asp:ListItem>
                            <asp:ListItem>手机号码已过期</asp:ListItem>
                        </asp:DropDownList>
                  </td>
                  
               <td align="center" width="5%" bgcolor="#FFFFFF" >
                  <asp:LinkButton ID="update" runat="server" CommandName="xiugai" >修改</asp:LinkButton>
                  <asp:LinkButton ID="LinkButton1" runat="server" Visible="false"  CommandName="save">保存</asp:LinkButton></td>
                  <td align="center" width="10%" bgcolor="#FFFFFF" >
                      <asp:LinkButton ID="detaile" runat="server"><a href='Gray_detail.aspx?id=<%# Eval("id") %>'>详细</a></asp:LinkButton>
                  </a></td>
                  <td><asp:Label ID="id" runat="server"  Visible="false" Text=' <%# Eval("id") %>'></asp:Label></td>
                </tr></table>
                    </ItemTemplate>                   
                </asp:TemplateField>
                      </Columns>
                      <EmptyDataTemplate>
                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#cce0f5">
                        <tr>
                          <td>没有找到数据!!</td>
                        </tr>
                        </table>
                      </EmptyDataTemplate>
                      <RowStyle HorizontalAlign= "Center " />
                  </asp:GridView>
                 
           </ContentTemplate>
              </asp:UpdatePanel>
     </ul>
     <ul>
          <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                  <ContentTemplate>
                       <webdiyer:AspNetPager ID="AspNetPager1" runat="server" 
             onpagechanged="AspNetPager1_PageChanged" PageIndexBoxType="DropDownList"  NumericButtonTextFormatString="【{0}】"
             TextAfterPageIndexBox=""
             ShowPageIndexBox="Always" SubmitButtonText="Go"   
             TextBeforePageIndexBox="转到" FirstPageText="首页" LastPageText="尾页" 
             NextPageText="下一页" PrevPageText="上一页">
    </webdiyer:AspNetPager>
                 
     </ul>
      </ContentTemplate>
                </asp:UpdatePanel>
  </div>

</div>
</div>

</div>

    </form>
</body>
</html>
分页控件使用的是AspNetPager,求高人指点,感激不尽
问题补充:

点击修改后回到第一页,所选择编辑的也是第一页的行和列点击进入的第二页界面

点击下一页后进入第二页页面url显示page=2,在第二页点击修改后页面回到第一页,但显示还是page=2,求各位大神解释是什么原因啊

Cleonard的主页 Cleonard | 初学一级 | 园豆:89
提问于:2012-04-21 17:41
< >
分享
最佳答案
0
     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                vf_findblaclist(1);
            }
        }
收获园豆:30
無限遐想 | 老鸟四级 |园豆:3740 | 2012-04-21 18:12

我之前试过,加了 if (!IsPostBack)后,分页都分不了了

Cleonard | 园豆:89 (初学一级) | 2012-04-23 08:47

@Cleonard: 分不了?爲什麽呢?這個不會吧。那你調試看看。怎麼回事呢?

無限遐想 | 园豆:3740 (老鸟四级) | 2012-04-23 09:31
其他回答(1)
0

上代码?

yj4018no1 | 园豆:181 (初学一级) | 2012-04-22 16:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册