首页 新闻 搜索 专区 学院

gridviwe用linkbutton编辑单元格时点击其他页的linkbutton总是回到第一页

0
悬赏园豆:10 [已关闭问题] 关闭于 2012-04-21 17:35
前台代码
 1  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
 2               <ContentTemplate>
 3                     <asp:GridView ID="GridView1" runat="server"  Width="768px"  
 4                         AutoGenerateColumns="False" 
 5                         onrowcreated="GridView1_RowCreated" onrowcommand="GridView1_RowCommand" >
 6                       <Columns>
 7                          <asp:TemplateField>
 8                     <HeaderTemplate>
 9                         <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#cce0f5">
10                 <tr>
11                   <td width="20%" height="25" align="center" bgcolor="#ebf5f5"><strong>被定位手机号码</strong></td>
12                   <td width="20%" align="center" bgcolor="#ebf5f5"><strong>手机主人</strong><strong></strong></td>
13                   <td width="50%" align="center" bgcolor="#ebf5f5"><strong class="shixiao">确认失败原因</strong><strong class="shixiao"></strong></td>
14                   <td width="5%" align="center" bgcolor="#ebf5f5"><strong>修改</strong></td>
15                   <td width="10%" align="center" bgcolor="#ebf5f5"><strong>详细</strong></td>
16                 </tr>
17                 </table>
18                     </HeaderTemplate>
19                     <ItemTemplate>
20                 <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#cce0f5">
21                 <tr>
22                   <td height="25" align="center" width="20%" bgcolor="#FFFFFF"><%# Eval("mobile")%></td>
23                   <td height="25" align="center" width="20%" bgcolor="#FFFFFF"><%# Eval("username ")%></td>
24                   <td height="25" align="center" width="50%" bgcolor="#FFFFFF">
25                   <asp:Label ID="reason" runat="server" Text=' <%# Eval("lost_reason") %>'></asp:Label>
26                   <asp:DropDownList ID="dropreason" runat="server" Visible="false" AutoPostBack="false">
27                             <asp:ListItem>手机已关机</asp:ListItem>
28                             <asp:ListItem>手机号码已停机</asp:ListItem>
29                             <asp:ListItem>手机号码已过期</asp:ListItem>
30                         </asp:DropDownList>
31                   </td>
32                   
33                <td align="center" width="5%" bgcolor="#FFFFFF" >
34                   <asp:LinkButton ID="update" runat="server" CommandName="xiugai" >修改</asp:LinkButton>
35                   <asp:LinkButton ID="LinkButton1" runat="server" Visible="false"  CommandName="save">保存</asp:LinkButton></td>
36                   <td align="center" width="10%" bgcolor="#FFFFFF" >
37                       <asp:LinkButton ID="detaile" runat="server"><a href='Gray_detail.aspx?id=<%# Eval("id") %>'>详细</a></asp:LinkButton>
38                   </a></td>
39                   <td><asp:Label ID="id" runat="server"  Visible="false" Text=' <%# Eval("id") %>'></asp:Label></td>
40                 </tr></table>
41                     </ItemTemplate>                   
42                 </asp:TemplateField>
43                       </Columns>
44                       <EmptyDataTemplate>
45                         <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#cce0f5">
46                         <tr>
47                           <td>没有找到数据!!</td>
48                         </tr>
49                         </table>
50                       </EmptyDataTemplate>
51                       <RowStyle HorizontalAlign= "Center " />
52                   </asp:GridView>
53                  
54            </ContentTemplate>
55               </asp:UpdatePanel>
56      </ul>
57      <ul>
58           <asp:UpdatePanel ID="UpdatePanel2" runat="server">
59                   <ContentTemplate>
60                        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" 
61              onpagechanged="AspNetPager1_PageChanged" PageIndexBoxType="DropDownList"  NumericButtonTextFormatString="【{0}】"
62              TextAfterPageIndexBox=""
63              ShowPageIndexBox="Always" SubmitButtonText="Go"   
64              TextBeforePageIndexBox="转到" FirstPageText="首页" LastPageText="尾页" 
65              NextPageText="下一页" PrevPageText="上一页">
66     </webdiyer:AspNetPager>
67                  
68      </ul>
69       </ContentTemplate>
70                 </asp:UpdatePanel>
后台部分代码
 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);
        }
    }

 

 

后台部分代码
 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);
        }
    }
Cleonard的主页 Cleonard | 初学一级 | 园豆:89
提问于:2012-04-21 17:29
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册