我将如何从前一页的网格视图转移到另一个web表单的值
本文关键字:转移 另一个 web 表单 视图 网格 一页 | 更新日期: 2023-09-27 17:53:00
如何将gridview的值传递到下一个webform?我的gridview代码如下:
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:LinkButton ID ="lnkEdit" runat="server" Text="View" PostBackUrl='<%# "Details.aspx?RowIndex=" + Container.DataItemIndex %>'></asp:LinkButton>
</ItemTemplate
</asp:TemplateField>
但我似乎不能使它工作。它转到下一个表单,但没有得到值。我的id有一个格式"1000001",它确实读取它。
这是我为下一页编写的代码。我创建了一个新的gridview来存储。
int rowIndex = int.Parse(Request.QueryString["RowIndex"]);
GridView gv1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
GridViewRow row = GridView1.Rows[rowIndex];
lblID.Text = row.Cells[0].Text;
添加OnRowCommand="GridView_RowCommand"
like
<asp:GridView ID="GridView" OnRowCommand="GridView_RowCommand"
将列更新为
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:LinkButton ID ="lnkEdit" runat="server" Text="View" CommandName= "Redirect" CommandArgument='<%#Eval("ID")%>' ></asp:LinkButton>
</ItemTemplate
代码隐藏文件
protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Redirect") {
//Get Command Argument
Response.Redirect("Details.aspx?RowIndex="+e.CommandArgument.ToString(),true);
}
}