如何将网格视图值传输到下一页 [英] How Do I Transfer Grid view values to next page
本文介绍了如何将网格视图值传输到下一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将网格视图值传输到下一页。网格视图包含一个文本框(txtItemGroup),其中的值必须由用户动态输入,而不是从数据库输入。
How Do I Transfer Grid view values to next page. Grid view consist one of the text box(txtItemGroup) which values have to be entered by the user dynamically, not from the Data base.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" HorizontalAlign="Center">
<Columns>
<asp:TemplateField HeaderText="Item Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("TestItemName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Items Group">
<ItemTemplate>
<asp:Label ID="lblGroup" runat="server" Text='<%# Eval("TestItemGroup") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Group">
<ItemTemplate>
<asp:TextBox ID="txtItemGroup" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Values">
<ItemTemplate>
<asp:Label ID="lblItemValue" runat="server" Text='<%# Eval("TestItemValues") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Default Values">
<ItemTemplate>
<asp:Label ID="lblDefaultValues" runat="server" Text='<%# Eval("DefaultValues") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
推荐答案
使用会话
和DataTable
简单,
源页面
UseSession
andDataTable
Simply,
Source Page
Gridview => Datatable
DataTable => Session
目的地页面
Destination Page
Session=> DataTable
如何将DataTable传递给Session&检索?
http: //stackoverflow.com/questions/2288299/storing-and-retrieving-datatable-from-session [ ^ ]
在第1页:
In Page 1:
protected void btnSend1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
string ItemGroup = ((TextBox)row.FindControl("txtItemGroup")).Text;
string ItemID = ((Label)row.FindControl("lblGroup12")).Text;
if (ItemGroup != null)
{
Update(ItemGroup,ItemID);
}
}
int ID = Convert.ToInt32(txtID.Text);
string url = "Default2.aspx?TestID=" + ID;
string fullURL = "window.open('" + url + "', '_blank');";
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", fullURL,true);
}
public void Update(string ItemGroup, string ItemID)
{
int Itemid = Convert.ToInt32(ItemID);
con = new SqlConnection(constr);
sqlstr = "update Test_Items set ItemGroup = '" + ItemGroup + "' where TestItemID = " + Itemid+"";
SqlCommand cmd = new SqlCommand(sqlstr, con);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
}
第2页:
In Page 2:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ID = Convert.ToInt32(Request.QueryString["TestID"]);
lblTestID.Text = ID.ToString();
}
Foo();
}
public void Foo()
{
sqlstr = "select * from Test_Items where TestID = '"+ID+"'";
SqlDataAdapter da = new SqlDataAdapter(sqlstr, con);
DataTable ds = new DataTable();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
这篇关于如何将网格视图值传输到下一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文