Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

XML
<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>
Posted
Updated 19-Mar-15 22:28pm
v3

Use Session and DataTable

Simply,
Source Page

Gridview => Datatable
DataTable => Session


Destination Page

Session=> DataTable

How to Pass DataTable to Session & Retrieve?

http://stackoverflow.com/questions/2288299/storing-and-retrieving-datatable-from-session[^]
 
Share this answer
 
v2
Comments
vickycode4 20-Mar-15 3:26am    
Thank you sir, Without using Session is there any other solution.
King Fisher 20-Mar-15 3:30am    
I think its best one to do this.
vickycode4 20-Mar-15 5:18am    
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Send")
{
TextBox txt = (TextBox)GridView1.FindControls("txtItemGroup");
Session["ItemGroup"] = txt.Text;
}
}

In Other Page:

if (!IsPostBack)
{
string sd = Session["ItemGroup"].ToString();
}

Sir, I tried This one. But It is showing FindControl error,
King Fisher 20-Mar-15 5:40am    
In which control you have Command name?
King Fisher 20-Mar-15 5:42am    
Try this

if (e.CommandName == "Send")
{
ImageButton image = (ImageButton)e.CommandSource as ImageButton;
GridViewRow row = image.NamingContainer as GridViewRow;
TextBox user_id = (TextBox )row.FindControl("txtItemGroup");
}
In Page 1:
C#
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();
        }


In Page 2:
C#
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();
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900