You need to find the row control of which butten is clicked and then you need to pass the value of all the controls using querystring to your webpage2.
on webpag2 using this querystring you can put values into the textbox.
when I tried above logic .I was able to go to the webpage2.aspx page but the data from gridview was not displayed into textbox and i dnt why itz happening like this....
niranjan479
Member
34 Points
75 Posts
Gridview Problem
Jun 09, 2012 10:53 AM|LINK
Hello guys,
I have two webpages in my application i.e., web1.aspx and web2.aspx. In web1.aspx i have a Gridview with auto generate select button.
so, when I click the select button of particular row of Gridview that row particular column data to be displayed into textbox of web2.aspx page..
Guys please help, i have been facing this pblm but couldn't find the solution..I hope you will provide the solution..
Thank you.
tarunSaini
Contributor
2948 Points
985 Posts
Re: Gridview Problem
Jun 09, 2012 10:54 AM|LINK
what error are you get?
Rk Hirpara
Member
2 Points
2 Posts
Re: Gridview Problem
Jun 09, 2012 12:13 PM|LINK
Name first page as WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%-- webPage1--%> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:gridview runat="server" ID="gridview1" AutoGenerateSelectButton="True" BorderStyle="Solid" onselectedindexchanged="gridview1_SelectedIndexChanged"> </asp:gridview> </div> <asp:Button runat="server" Text="Next" onclick="Next_Click"/> </form> </body> </html>The code file is as follow for your first page
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace WebApplication1 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Columns.Add("Surname"); dt.Rows.Add("Rk", "Hirpara"); dt.Rows.Add("Mark", "Twain"); dt.Rows.Add("Imar", "Spaanjaar"); dt.Rows.Add("Jerry", "Bank"); dt.Rows.Add("Shreya", "Shah"); gridview1.DataSource = dt; gridview1.DataBind(); } protected void gridview1_SelectedIndexChanged(object sender, EventArgs e) { Session["Name"] = (gridview1.Rows[gridview1.SelectedIndex].Cells[1].Text); } protected void Next_Click(object sender, EventArgs e) { Response.Redirect("~/WebForm2.aspx"); } } }Name first page as WebForm2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> Selected Name : <asp:TextBox ID="txtName" runat="server"></asp:TextBox> </div> </form> </body> </html>The code for your second page is as follow
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { txtName.Text = Session["Name"] != null ? Session["Name"].ToString() : ""; } } }// If this is not what u wanted then please clarify the problem definition in detail and if resolved then you have
more option to do this like using queryString, Cookie, or dataBase, ViewState.
Thanks and Regards,
Rk_Hirpara
niranjan479
Member
34 Points
75 Posts
Re: Gridview Problem
Jun 09, 2012 12:50 PM|LINK
i dont know the logic for the query..
thanks for ur reply
sanjayverma_...
Participant
1568 Points
361 Posts
Re: Gridview Problem
Jun 09, 2012 01:01 PM|LINK
Hi,
You need to find the row control of which butten is clicked and then you need to pass the value of all the controls using querystring to your webpage2.
on webpag2 using this querystring you can put values into the textbox.
or it will be like this
<asp:TemplateField HeaderText="Command"> <ItemTemplate> <a href='webpage2.aspx.aspx?Id=<%# Eval("ProductId")%> &&ProductName=<%# Eval("ProductName")%>'>Send To webpage2</a> </ItemTemplate> </asp:TemplateField> //On webpage2 pageloadevent textbox1.Text=Request.QueryString["Id"].ToString(); textbox2.Text=Request.QueryString["ProductName"].ToString();niranjan479
Member
34 Points
75 Posts
Re: Gridview Problem
Jun 09, 2012 01:03 PM|LINK
I have implemented the logic by using sessions,cookies and query string but the data from row was not displayed in the textbox..
niranjan479
Member
34 Points
75 Posts
Re: Gridview Problem
Jun 09, 2012 03:25 PM|LINK
when I tried above logic .I was able to go to the webpage2.aspx page but the data from gridview was not displayed into textbox and i dnt why itz happening like this....
Please help me..Hirpara.
niranjan479
Member
34 Points
75 Posts
Re: Gridview Problem
Jun 10, 2012 09:41 AM|LINK
guys please help me in solving the above problem
sanjayverma_...
Participant
1568 Points
361 Posts
Re: Gridview Problem
Jun 11, 2012 04:48 AM|LINK
Hi ,
Please post your code so that it will be more clear to us .
niranjan479
Member
34 Points
75 Posts
Re: Gridview Problem
Jun 11, 2012 05:06 AM|LINK
Webpage1.aspx code:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>
<br />
</p>
<asp:GridView ID="GridForums" runat="server" AllowPaging="True"
AutoGenerateColumns="False" AutoGenerateSelectButton="True"
onselectedindexchanging="GridForums_SelectedIndexChanging"
style="z-index: 1; left: 282px; top: 350px; position: absolute; height: 265px; width: 664px"
BorderColor="#FF6600"
onpageindexchanging="GridForums_PageIndexChanging">
<Columns>
<asp:TemplateField HeaderText="Questions">
<ItemTemplate>
<%#Eval("Question") %>
</ItemTemplate>
<HeaderStyle BorderColor="#3399FF" BorderStyle="Groove" ForeColor="Yellow" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Tag">
<ItemTemplate>
<%#Eval("Tag") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lbldesc" runat="server" Text='<%#Eval("Description") %> ' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#3399FF" BorderColor="#3399FF" BorderStyle="Groove"
ForeColor="Yellow" HorizontalAlign="Center" />
</asp:GridView>
</asp:Content>
Webpage2.aspx code:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Font-Size="Medium" Font-Underline="True"
ForeColor="#FF33CC"
style="z-index: -1; left: 320px; top: 336px; position: absolute"
Text="Question Description"></asp:Label>
<asp:TextBox ID="txqtnDesc" runat="server" BorderStyle="Groove"
Font-Size="Medium" ForeColor="Black"
style="z-index: -1; left: 318px; top: 369px; position: absolute; height: 216px; width: 481px; right: 505px"
TextMode="MultiLine" AutoPostBack="True" ValidationGroup="grp1"></asp:TextBox>
<asp:Button ID="btnReply" runat="server" BackColor="#0066FF"
onclick="btnReply_Click"
style="z-index: 1; left: 379px; top: 630px; position: absolute; width: 75px"
Text="Reply" />
<asp:Button ID="btnCancel" runat="server" BackColor="#0066FF"
onclick="btnCancel_Click"
style="z-index: 1; left: 620px; top: 632px; position: absolute; width: 71px"
Text="Cancel" />
</asp:Content>
.........................................................................
So when a user selects a 1st row that row's third cell i want it to be displayed into webpage2.aspx textbox....
I hope this would be clear....Help me.