0

私のグリッド ビューでは、ユーザーがアクティブ化をクリックすると、activate.aspx ページに移動します。そして、前のページから activate.aspx ページに 3 つの値を取得したいと考えています。私のコードは次のとおりです。

    if (this.Page.PreviousPage != null)
    {
        int rowIndex = int.Parse(Request.QueryString["RowIndex"]);
        GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
        GridViewRow row = GridView1.Rows[rowIndex];
        Label1.Text = row.Cells[3].Text;
        Label2.Text = row.Cells[2].Text;
        Label3.Text = row.Cells[2].Text;
        SqlDataAdapter da = new SqlDataAdapter("insert into login values('" + Label1.Text + "','" + Label2.Text + "','" + Label3.Text + "')",con);
        DataSet ds = new DataSet();
        da.Fill(ds);
      }

マークアップ:

   <asp:TemplateField HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="Larger" HeaderText="Activate/Delete" ItemStyle-Width="150px">
                <ItemTemplate>                    
                    <asp:LinkButton ID="linkbutton1" runat="server" Text="Activate" PostBackUrl='<%# "activate.aspx?RowIndex=" + Container.DataItemIndex %>' ></asp:LinkButton>              
                    <span onclick="return confirm('Are You sure want to Delete?')">
                    <asp:LinkButton ID="linkbutton2" runat="server" Text="Delete" CommandName="Delete"></asp:LinkButton>
                    </span>
                </ItemTemplate>    
            </asp:TemplateField>  

しかし、前のページの値を取得できません。

助けてください。

4

3 に答える 3

0
<asp:LinkButton ID="linkbutton1" runat="server" Text="Activate" CommandArgument="linkbutton1" PostBackUrl='<%# "activate.aspx?RowIndex=" + Container.DataItemIndex %>' ></asp:LinkButton>

そのようにコマンド引数を入れてください。

于 2015-04-02T06:06:09.907 に答える
0

PostBackUrlを介して現在のページをactivate.aspxに移動しています。基本的にはResponse.Redirect("");として機能します。これで、前のページのメモリが解放されました。Server.Transfer("activate.aspx",true);をナビゲートする必要があります。GridView の RowCommand を使用して、現在のページのバックエンド コードから。

Aspx ページのマークアップ:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" 
            onrowcommand="GridView1_RowCommand">
            <Columns>
                <asp:TemplateField HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="Larger" HeaderText="Activate/Delete"
                    ItemStyle-Width="150px">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkbutton1" runat="server" Text="Activate" CommandName="Redirect"
                            CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'></asp:LinkButton>
                        <span onclick="return confirm('Are You sure want to Delete?')">
                            <asp:LinkButton ID="linkbutton2" runat="server" Text="Delete" CommandName="Delete"></asp:LinkButton>
                        </span>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

.cs ページ コード:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Redirect")
        {
            String yourId="What ever id you want pass";
            Server.Transfer("activate.aspx?RowIndex=" + yourId, true);
        }
    }
于 2013-10-28T06:24:56.677 に答える