Getting values from the Gridview and put it in the previous form?http://forums.asp.net/t/1143217.aspx/1?Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Tue, 28 Aug 2007 04:42:30 -040011432171844417http://forums.asp.net/p/1143217/1844417.aspx/1?Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Getting values from the Gridview and put it in the previous form? <p>Hello everyone,</p> <p>&nbsp;</p> <p>I want to get the data from the Gridview and put t in the previous form, how do I do it? </p> <p><font><font size="3"></p> <pre><font color="blue"><b><font color="blue">&lt;%</font>@ Page Language=&quot;C#&quot; <font color="blue">%&gt;</font></b></font></pre> <pre><font color="blue"><b><font color="blue">&lt;%@ Reference Page=&quot;~/webform1.aspx&quot; %&gt;</font></b></font><br><font color="blue">&lt;</font><font color="maroon">html</font><font color="blue">&gt;</font><br> <font color="blue">&lt;</font><font color="maroon">head</font> runat=&quot;server&quot;<font color="blue">&gt;</font><br> <font color="blue">&lt;</font><font color="maroon">title</font><font color="blue">&gt;</font>View Information<font color="blue">&lt;/</font><font color="maroon">title</font><font color="blue">&gt;</font><br> <font color="blue">&lt;/</font><font color="maroon">head</font><font color="blue">&gt;</font><br> <font color="blue">&lt;</font><font color="maroon">body</font><font color="blue">&gt;</font><br> <font color="blue">&lt;</font><font color="maroon">form</font> id=&quot;form1&quot; runat=&quot;server&quot;<font color="blue">&gt;</font><br><font color="blue"><b> &lt;asp:GridView ID=&quot;GridView1&quot; AllowSorting=&quot;true&quot; AllowPaging=&quot;true&quot; Runat=&quot;server&quot;<br> DataSourceID=&quot;SqlDataSource1&quot; AutoGenerateEditButton=&quot;true&quot; DataKeyNames=&quot;au_id&quot;<br> AutoGenerateColumns=&quot;False&quot;&gt;</b></font><br> <font color="blue">&lt;</font><font color="maroon">Columns</font><font color="blue">&gt;</font><br> <font color="blue">&lt;</font><font color="blue"><b>asp:BoundField ReadOnly=&quot;true&quot; HeaderText=&quot;ID&quot; DataField=&quot;au_id&quot; SortExpression=&quot;au_id&quot; <font color="blue">/&gt;</font></b></font><br> <font color="blue">&lt;</font><font color="blue"><b>asp:BoundField HeaderText=&quot;Last Name&quot; DataField=&quot;au_lname&quot; SortExpression=&quot;au_lname&quot; <font color="blue">/&gt;</font></b></font><br> <font color="blue">&lt;</font><font color="blue"><b>asp:BoundField HeaderText=&quot;First Name&quot; DataField=&quot;au_fname&quot; SortExpression=&quot;au_fname&quot; <font color="blue">/&gt;</font></b></font></pre> <pre><font><font size="3"><pre> <font color="blue">&lt;/</font><font color="maroon">Columns</font><font color="blue">&gt;</font><br> <font color="blue">&lt;/</font><font color="blue"><b>asp:GridView<font color="blue">&gt;</font></b></font><br> <font color="blue">&lt;/</font><font color="maroon">form</font><font color="blue">&gt;</font><br> <font color="blue">&lt;/</font><font color="maroon">body</font><font color="blue">&gt;</font><br><font color="blue">&lt;/</font><font color="maroon">html</font><font color="blue">&gt;</font></pre><pre>&nbsp;</pre><pre><b>In Form1.aspx</b></pre><pre>ControlID=txtFName.Text</pre><pre>ControlID=txtLName.Text</pre><pre><b>In GridView&nbsp;</b></pre><pre> protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)<br> { </pre><pre> Session.Add(txtFName.Tex), me.GridView1.SelectedRow.Cells(0).Text) //<br></pre><pre> Session.Add((txtLName.Tex), me.GridView1.SelectedRow.Cells(1).Text); </pre><pre> OR</pre><pre> string x;<br> string Contact = new newContact();<br> newTextbox = GridView1.rows(x).controls.findcontrol(&quot;au_fname&quot;);<font><font><font><font><font><font size="3"><pre><font><font size="3"><pre> .....................................}</pre><pre>&nbsp;&nbsp;</pre><pre>&nbsp;</pre></font></font></pre></font></font></font></font></font></font>&nbsp;</pre></font></font>&nbsp;</pre> </font></font>&nbsp; <p></p> <p>&nbsp;</p> 2007-08-07T04:56:55-04:001845408http://forums.asp.net/p/1143217/1845408.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>any one?&nbsp; thanks</p> 2007-08-07T15:10:15-04:001846928http://forums.asp.net/p/1143217/1846928.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi:</p> <p>&nbsp; Have you tried PreviousPage.FindControl() method?</p> <p>&nbsp; If your problem remains, please tell us the difficulty you meet with.</p> <p>Thanks</p> 2007-08-08T09:31:18-04:001847497http://forums.asp.net/p/1143217/1847497.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>No, I haven't use the PreviousPage.FindControl() method.. How do I do that?</p> <p>I just put the&nbsp;&nbsp; <font size="2">&lt;%</font><font color="#0000ff" size="2">@</font><font size="2"> </font><font color="#800000" size="2">Reference</font><font size="2"> </font><font color="#ff0000" size="2">Page</font><font color="#0000ff" size="2">=&quot;~/Form1.aspx&quot;</font><font size="2"> %&gt; in the Gridview page to reference Form1 page, then in the Gridview, I try this but gets </font>Error&nbsp;&nbsp;'System.Web.UI.WebControls.GridView' does not contain a definition for 'rows'&nbsp;<br> </p> <font size="2"><font color="#0000ff" size="2">protected</font><font size="2"> </font> <font color="#0000ff" size="2">void</font><font size="2"> GridView1_SelectedIndexChanged(</font><font color="#0000ff" size="2">object</font><font size="2"> sender, </font><font color="#008080" size="2">EventArgs</font><font size="2"> e)</font></font><font size="2"> <p>{string x;</p> </font><font color="#008080" size="2">Form1</font><font size="2"> form = </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">Form1</font><font size="2">();</font><font size="2"> <p>form.Lname = GridView1.rows(x).controls.findcontrol(</font><font color="#800000" size="2">&quot;LastName&quot;</font><font size="2">);</font></p> <p><font size="2">OR</font></p> <font size="2"><font color="#008000" size="2"> <p>Session.Add(&quot;LName&quot;, GridView1.SelectedRow.Cells(0).Text);</p> <font size="2"><font size="2"> <p><font size="2">Server.Transfer(</font><font color="#800000" size="2">&quot;Form1.aspx&quot;</font><font size="2">);</p> </font></font></font><font size="2"> <p>}</p> <p>}</p> <p>Can you show me how to use the PreviousPage.FindControl() method to get the values from Gridview and put it back&nbsp;in the textbox of Form1, thanks</p> <p>&nbsp;</p> <p><br> &nbsp;</p> </font></font></font> <p>&nbsp;</p> 2007-08-08T14:34:56-04:001848619http://forums.asp.net/p/1143217/1848619.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi:</p> <p>&nbsp; C# is case sensitive,&nbsp;so it should be GridView1.Rows[x].Controls.FindControl(&quot;LastName&quot;);</p> <p>&nbsp; From your code I think what you're doing now is the opposition to your thread. It's better to clarify what do you want to do.</p> <p>&nbsp; Please elaborate your requirement. </p> <p>&nbsp; And here's&nbsp;how to use PreviousPage.FindControl():</p> <p>&nbsp; Control c=PreviousPage.FindControl(&quot;ControlID&quot;);</p> <p>Thanks &amp; Regards<br> </p> 2007-08-09T01:21:12-04:001848770http://forums.asp.net/p/1143217/1848770.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Thanks Allen for replying,</p> <p>Okay, let me clarify it, hopefully I won't confuse you hihi....<br> </p> <p>I have a webform.aspx and 3 control buttons on the form &quot;<b>Save</b>, <b>View All Data</b> (all data from webform Db) and <b>Next</b>&quot; button, The &quot;Save&quot; button is saving all the information on the form to the access database and the &quot;View All Data&quot; is pull out all the information from that webform database and put it in the Gridview. When user view all the data on the Gridview and decided to select the information on Row 5 for either edit or continue on running a search. The row 5 that the user select should be pre-populate all the information on that Row back to the webform, How do I pass variables or values from the Gridview back to the webform?</p> <p>&nbsp;For Example:</p> <pre><b><span style="color:blue">&lt;asp:GridView ID=&quot;GridView1&quot; </span></b><br><br><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">&lt;</span><span style="color:maroon">Columns</span><span style="color:blue">&gt;</span><br><br><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">&lt;<b>asp:BoundField ReadOnly=&quot;true&quot; HeaderText=&quot;ID&quot; DataField=&quot;au_id&quot; SortExpression=&quot;au_id&quot; /&gt;</b></span><br><br><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">&lt;<b>asp:BoundField HeaderText=&quot;Last_Name&quot; DataField=&quot; Last_Name &quot; /&gt;</b></span><br><br><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">&lt;<b>asp:BoundField HeaderText=&quot;First_Name&quot; DataField=&quot; First_Name &quot;/&gt;</b></span></pre> <pre><b><span style="color:blue"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b></pre> <pre> <span style="color:blue">&lt;/</span><span style="color:maroon">Columns</span><span style="color:blue">&gt;</span><br><br><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">&lt;/<b>asp:GridView&gt;</b></span><br style=""><br><br style=""></pre> <pre><b>In Form1.aspx</b></pre> <pre>ControlID=txtLName.Text</pre> <pre>ControlID=txtFName.Text</pre> <pre>&nbsp;</pre> <pre><b>In Select handler, I include Reference Page and PreviousPageType in the source of Gridview</b></pre> <pre><b> &lt;%@ Reference Page=&quot;~/RegionBankForm.aspx&quot; %&gt;<br>&lt;%@ PreviousPageType VirtualPath=&quot;RegionBankForm.aspx&quot; %&gt;</b></pre> <pre> protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)<br> {</pre> <pre>&nbsp; string x;<br> GridView1.Rows[x].Controls.FindControl(&quot;<span style="color:blue"><b><b>Last_Name</b></b></span>&quot;); <b><b><br> </b></b>Control txtLName = (TextBox)PreviousPage.FindControl(&quot;txLName&quot;); <b><b> </b></b></pre> <pre><b><b> </b></b> GridView1.Rows[x].Controls.FindControl(&quot;<span style="color:blue"><b><b>First_Name</b></b></span>&quot;); <b><b><br> </b></b>Control txtFName = (TextBox)PreviousPage.FindControl(&quot;txFName&quot;); </pre> <pre><span id="listComments_ctl02_labelComment" class="commenttext">Response.Direct(</span>txLName<span id="listComments_ctl02_labelComment" class="commenttext">.Text&#43;&quot;&lt;br&gt;&quot;&#43;</span>txFName<span id="listComments_ctl02_labelComment" class="commenttext">.Text&#43;&quot;&lt;br&gt;&quot;);</span><br><b><b> </b></b> <br>//<b><b>But I got errors: 'System.Web.UI.WebControls.GridViewRowCollection.this[int]' has some invalid </b></b><b><b><b><b> arguments and </b></b></b>System.Data.OleDb.OleDbException: Disk or network error.</b></pre> <pre>// <b>Can you show me the right way to do it ? thanks</b> <br></pre> <pre> &nbsp;<br></pre> <pre>&nbsp;</pre> <pre>}&nbsp;</pre> 2007-08-09T03:55:03-04:001848914http://forums.asp.net/p/1143217/1848914.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi:</p> <p>&nbsp; Thank you for your updating but I'm afraid I'm still confused. Here's my question:</p> <p>1. The GridView is in webform.aspx and when user selects one row he'll be redirected to Form1.aspx?</p> <p>2. You want to show some information&nbsp;of the selected row on page Form1.aspx?</p> <p>&nbsp; If my understanding is correct. Here's the suggestion:</p> <p>&nbsp;You can use QueryString to pass values. For example:</p> <p>&nbsp;protected void GridView1_<strong>SelectedIndexChanging</strong>(object sender, GridViewSelectEventArgs e)&nbsp; <strong>//Note the event handler isnot SelectedIndexChanged</strong><br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp; string s=((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[0]).Text://You can set a breakpoint here to test the index</p> <p>&nbsp;&nbsp;&nbsp; &nbsp; Response.Redirect(&quot;Form1.aspx?A=&quot; &#43; s);<br> &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp; in Form1.aspx.cs's Page_Load&nbsp;you can get querystring:</p> <p><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Request.QueryString[&quot;A&quot;] != null) <br> { </p> <p>txtLName.Text= Request.QueryString[&quot;A&quot;]; </p> <p>}</p> <p>Regards</p> 2007-08-09T05:45:14-04:001849683http://forums.asp.net/p/1143217/1849683.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Thankyou Allen for all your help, really appreciated!&nbsp; </p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Allen Chen MSFT</h4> <p>1. The GridView is in webform.aspx and when user selects one row he'll be redirected to Form1.aspx?</p> </blockquote> <p></p> <p>Yes, the GridView is in webform.aspx and when user click &quot;View Detail&quot; button on Form1, It pops up with all data in the Gridview</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Allen Chen MSFT</h4> <p></p> <p>2. You want to show some information&nbsp;of the selected row on page Form1.aspx?</p> </blockquote> <p></p> <p>Yes, that's correct, How do I pass all the row information into form1?&nbsp; I have&nbsp;&nbsp;about 30 columns in Gridview and about 30 textfields in Form1</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Allen Chen MSFT</h4> <p></p> <p>&nbsp;protected void GridView1_<strong>SelectedIndexChanging</strong>(object sender, GridViewSelectEventArgs e)&nbsp; <strong>//Note the event handler isnot SelectedIndexChanged</strong><br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp; string s=((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[0]).Text://You can set a breakpoint here to test the index</p> <p>&nbsp;&nbsp;&nbsp; &nbsp; Response.Redirect(&quot;Form1.aspx?A=&quot; &#43; s);<br> &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp; in Form1.aspx.cs's Page_Load&nbsp;you can get querystring:</p> <p><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Request.QueryString[&quot;A&quot;] != null) <br> { </p> <p>txtLName.Text= Request.QueryString[&quot;A&quot;]; </p> <p>}</p> <p></p> </blockquote> <p></p> <p><strong>I have an error at Compiler Error Message: </strong>CS0117: 'System.EventArgs' does not contain a definition for 'NewSelectedIndex'</p> <p><font color="#ff0000">Line 29:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string s = ((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[0]).Text; //You can set a breakpoint here to test the index<br> </font></p> 2007-08-09T12:40:39-04:001851001http://forums.asp.net/p/1143217/1851001.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi:</p> <p>&nbsp; Thanks for your further elaboration. Then you can just try what I mentioned in my previous post. </p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>boston_ma</h4> <p><strong>I have an error at Compiler Error Message: </strong>CS0117: 'System.EventArgs' does not contain a definition for 'NewSelectedIndex'</p> <p><font color="#ff0000">Line 29:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string s = ((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[0]).Text; //You can set a breakpoint here to test the index<br> </font></p> <p></p> </blockquote> <p></p> <p>&nbsp; About this error, please make sure in your inline code you're specifying the correct event:</p> <p><strong>&nbsp;OnSelectedIndexChanging</strong>=&quot;GridView1_SelectedIndexChanging&quot;</p> <p>&nbsp; Note it's&nbsp;<strong>NOT</strong> <strong>OnSelectedIndexChanged.</strong></p> <p>If you sill get this error, please inform us.</p> <p>Regards</p> 2007-08-10T01:34:44-04:001851042http://forums.asp.net/p/1143217/1851042.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Allen Chen MSFT</h4> <p></p> <p>&nbsp; About this error, please make sure in your inline code you're specifying the correct event:</p> <p><b>&nbsp;OnSelectedIndexChanging</b>=&quot;GridView1_SelectedIndexChanging&quot;</p> <p>&nbsp; Note it's&nbsp;<b>NOT</b> <b>OnSelectedIndexChanged.</b></p> <p>If you sill get this error, please inform us.</p> <p>Regards</p> <p></p> </blockquote> &nbsp; <p></p> <p>&nbsp;</p> <p>Thanks Allen for still helping me out, really appreciated :-)</p> <p>On the Gridview, I have set the&nbsp; Automatic Generate Select Button = true,&nbsp; when I double click on the select link on the Gridview, it generated the <b>OnSelectedIndexChanged Not&nbsp; </b><b>OnSelectedIndexChanging</b>=&quot;GridView1_SelectedIndexChanging&quot; , for right now it Redirect to form1 when click &quot;Select&quot; link but values are not showing.. I think it''s&nbsp; because the Select action is triggered the <b>OnSelectedIndexChanged not </b><b>OnSelectedIndexChanging,&nbsp; </b>so how do I link the Select Command to the <b>Gridview1_OnSelectedIndexChanging?</b></p> <p>&nbsp;</p> <p><br> </p> 2007-08-10T02:22:14-04:001851063http://forums.asp.net/p/1143217/1851063.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi:</p> <p>&nbsp; Please open your aspx. Shift to Source view. Then manually add this (and remove <strong>OnSelectedIndexChanged if it is there</strong>):</p> <p>&nbsp;&lt;asp:GridView <strong>OnSelectedIndexChanging=&quot;GridView1_SelectedIndexChanging&quot;&nbsp;</strong>ID=&quot;GridView1&quot; runat=&quot;server&quot;&gt;<br> &nbsp;&lt;/asp:GridView&gt;</p> <p>&nbsp; Or in design view, choose your GridView and click the yellow icon in the properties window, in the listed events below you can find SelectedIndexChanging and double click it.</p> <p>Regards</p> 2007-08-10T02:52:02-04:001851091http://forums.asp.net/p/1143217/1851091.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Allen Chen MSFT</h4> <p></p> <p>Hi:</p> <p>&nbsp; Please open your aspx. Shift to Source view. Then manually add this (and remove <strong>OnSelectedIndexChanged if it is there</strong>):</p> <p>&nbsp;&lt;asp:GridView <strong>OnSelectedIndexChanging=&quot;GridView1_SelectedIndexChanging&quot;&nbsp;</strong>ID=&quot;GridView1&quot; runat=&quot;server&quot;&gt;<br> &nbsp;&lt;/asp:GridView&gt;</p> <p>&nbsp; Or in design view, choose your GridView and click the yellow icon in the properties window, in the listed events below you can find SelectedIndexChanging and double click it.</p> <p></p> </blockquote> &nbsp; <p></p> <p>I did this already but still no luck, no values show in the form&nbsp;</p> 2007-08-10T03:14:38-04:001851117http://forums.asp.net/p/1143217/1851117.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi:</p> <p>&nbsp; Could you please post all your current code (both inline code and code behind of all your two pages)?</p> <p>Thanks</p> 2007-08-10T03:36:16-04:001851143http://forums.asp.net/p/1143217/1851143.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>I have about 30&#43; fields in the form and also the same amount of data on the Gridview pull out from the same database of where form1 save ...Do you want me to post all? let me know,&nbsp; I pull out just the first 3 to show you<br> </p> <p><b>Here is part of the Gridview Design form</b><br> </p> <p>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;RegionBankDetails.aspx.cs&quot; Inherits=&quot;RegionBankDetails&quot; %&gt;<br> &lt;%@ Reference Page=&quot;~/RegionBankForm.aspx&quot; %&gt;<br> <br> &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br> <br> &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;<br> &lt;head runat=&quot;server&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &lt;title&gt;RegionBankDetails&lt;/title&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br> &nbsp;&nbsp;&nbsp; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &lt;div&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; DataSourceID=&quot;SqlDataSource3&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Style=&quot;z-index: 100; left: 0px; position: absolute; top: 24px&quot; AllowPaging=&quot;True&quot; AllowSorting=&quot;True&quot; CellSpacing=&quot;2&quot; BackColor=&quot;#CCCCCC&quot; BorderColor=&quot;#999999&quot; BorderStyle=&quot;Solid&quot; BorderWidth=&quot;3px&quot; CellPadding=&quot;4&quot; ForeColor=&quot;Black&quot; OnSelectedIndexChanging=&quot;GridView1_SelectedIndexChanging&quot; AutoGenerateSelectButton=&quot;True&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Columns&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:BoundField DataField=&quot;File Num&quot; HeaderText=&quot;File Num&quot; InsertVisible=&quot;False&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SortExpression=&quot;File Num&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:BoundField DataField=&quot;LenderName&quot; HeaderText=&quot;LenderName&quot; SortExpression=&quot;LenderName&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:BoundField DataField=&quot;LenderEmail&quot; HeaderText=&quot;LenderEmail&quot; SortExpression=&quot;LenderEmail&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:BoundField DataField=&quot;LenderPhone&quot; HeaderText=&quot;LenderPhone&quot; SortExpression=&quot;LenderPhone&quot; /&gt;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .................................</p> <p>SortExpression=&quot;BorrowerInfoQues9Yes&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:CheckBoxField DataField=&quot;BorrowerInfoQues9No&quot; HeaderText=&quot;BorrowerInfoQues9No&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SortExpression=&quot;BorrowerInfoQues9No&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Columns&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;FooterStyle BackColor=&quot;#CCCCCC&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;RowStyle BackColor=&quot;White&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;SelectedRowStyle BackColor=&quot;#000099&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;PagerStyle BackColor=&quot;#CCCCCC&quot; ForeColor=&quot;Black&quot; HorizontalAlign=&quot;Left&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;HeaderStyle BackColor=&quot;Black&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:GridView&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:SqlDataSource ID=&quot;SqlDataSource3&quot; runat=&quot;server&quot; ConnectionString=&quot;&lt;%&#36; ConnectionStrings:bankConnectionString5 %&gt;&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ProviderName=&quot;&lt;%&#36; ConnectionStrings:bankConnectionString5.ProviderName %&gt;&quot; SelectCommand=&quot;SELECT * FROM [bank] ORDER BY [File Num]&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:SqlDataSource&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:SqlDataSource ID=&quot;SqlDataSource2&quot; runat=&quot;server&quot; ConnectionString=&quot;&lt;%&#36; ConnectionStrings:bankConnectionString4 %&gt;&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ProviderName=&quot;&lt;%&#36; ConnectionStrings:bankConnectionString4.ProviderName %&gt;&quot; SelectCommand=&quot;SELECT * FROM [bank] ORDER BY [File Num]&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:SqlDataSource&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:SqlDataSource ID=&quot;SqlDataSource1&quot; runat=&quot;server&quot; ConnectionString=&quot;&lt;%&#36; ConnectionStrings:bankConnectionString3 %&gt;&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ProviderName=&quot;&lt;%&#36; ConnectionStrings:bankConnectionString3.ProviderName %&gt;&quot; SelectCommand=&quot;SELECT * FROM [bank] ORDER BY [File Num]&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:SqlDataSource&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;nbsp;<br> &nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp; &lt;/div&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/form&gt;<br> &lt;/body&gt;<br> &lt;/html&gt;</p> <p>&nbsp;</p> <p><b>And Code Behind </b></p> <p><b>using System;<br> using System.Data;<br> using System.Configuration;<br> using System.Collections;<br> using System.Web;<br> using System.Web.Security;<br> using System.Web.UI;<br> using System.Web.UI.WebControls;<br> using System.Web.UI.WebControls.WebParts;<br> using System.Web.UI.HtmlControls;<br> <br> public partial class RegionBankDetails : System.Web.UI.Page<br> {<br> &nbsp;&nbsp;&nbsp; protected void Page_Load(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> <br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)&nbsp; //Note the event handler isnot SelectedIndexChanged<br> &nbsp;&nbsp;&nbsp; {<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string s = ((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[0]).Text;&nbsp; //You can set a breakpoint here to test the index<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string a = ((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[1]).Text;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string b = ((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[2]).Text; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Redirect(&quot;RegionBankForm.aspx?A=&quot; &#43; s &#43; &quot;B=&quot; &#43; a &#43; &quot;C=&quot; &#43; b );</b></p> <p><b>}</b></p> <p>&nbsp;</p> <p><b>And in Form1.aspx</b></p> <p>&nbsp;</p> <p>protected void Page_Load(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.TextBoxLenderName.Text = Request.QueryString[&quot;requestorname&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.TextBoxLenderEmail.Text = Request.QueryString[&quot;email&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((Request.QueryString[&quot;A&quot;] != null)&amp;&amp; (Request.QueryString[&quot;B&quot;] != null)&amp;&amp; (Request.QueryString[&quot;A&quot;] != null))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextBoxLName.Text = Request.QueryString[&quot;A&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextBoxLEmail.Text = Request.QueryString[&quot;B&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextBoxPhone.Text = Request.QueryString[&quot;C&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp; } <br> </p> <p><b><br> &nbsp;</b></p> 2007-08-10T04:03:53-04:001851168http://forums.asp.net/p/1143217/1851168.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi:</p> <p>&nbsp; Change this at first:</p> <p>&nbsp;Response.Redirect(&quot;RegionBankForm.aspx?A=&quot; &#43; s &#43; &quot;<strong>&amp;</strong>B=&quot; &#43; a &#43; &quot;<strong>&amp;</strong>C=&quot; &#43; b );</p> <p>&nbsp; And I'll keep looking into your code to see whether there're other problems.</p> <p>Thanks</p> 2007-08-10T04:36:42-04:001851188http://forums.asp.net/p/1143217/1851188.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>&nbsp;Still Nothing shows in the form, <br> </p> 2007-08-10T04:56:37-04:001851222http://forums.asp.net/p/1143217/1851222.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi:</p> <p>&nbsp;</p> <p>Hi:</p> <p>&nbsp; What can you see on the address bar? Also:</p> <p>protected void Page_Load(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.TextBoxLenderName.Text = Request.QueryString[&quot;requestorname&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.TextBoxLenderEmail.Text = Request.QueryString[&quot;email&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((Request.QueryString[&quot;A&quot;] != null)&amp;&amp; (Request.QueryString[&quot;B&quot;] != null)&amp;&amp; (Request.QueryString[&quot;A&quot;] != null))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> <strong>string s= Request.QueryString[&quot;A&quot;];</strong><br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextBoxLName.Text = Request.QueryString[&quot;A&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextBoxLEmail.Text = Request.QueryString[&quot;B&quot;];<br> &nbsp;&nbsp;<strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextBoxPhone.Text = Request.QueryString[&quot;C&quot;];//Set a breakpoint&nbsp;here.&nbsp;What's the value of s?<br> </strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp; } <br> Regards</p> 2007-08-10T05:21:04-04:001851809http://forums.asp.net/p/1143217/1851809.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Sorry for a late reply , Thanks Allen for your patient and your support...</p> <p>It works perfectly now, It put appropriate values from the row column to the field in the form but I'm afraid that the Querry String for Response Direct have a limit of max string. I have 40 columns in the Gridview and that 40 variable fields have to populate all in the &nbsp;form.</p> <p>Is there a way to breakdown the Query String?</p> 2007-08-10T12:44:39-04:001853979http://forums.asp.net/p/1143217/1853979.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi Allen,</p> <p>Instead of using a long Query String to pass variables back to the form, So, I use the String Session to pass variable back to the form and it works, but when I want to get the checkbox checked from Gridview to the form, it gets error saying CS0117: 'System.Web.UI.WebControls.TableCell' does not contain a definition for 'Checked', so how do I declare the &quot;System.Web.UI.WebControls.TableCell&quot; for the checkbox? I use the boolean but it's not working, ...thanks<br> </p> <p>protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) <br> &nbsp;&nbsp;&nbsp; { <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //**Pass variables back to the Form1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session[&quot;A&quot;] = ((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[2]).Text;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session[&quot;B&quot;] = ((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[3]).Text;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session[&quot;CKB1&quot;] = ((TableCell)GridView1.Rows[e.NewSelectedIndex].Controls[30]).Checked;&nbsp;&nbsp; //NOT WORKS<br> &nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Response.Redirect(&quot;Form1.aspx&quot;);<br> &nbsp;</p> <p>}</p> <p>In Form1 Page_Load:</p> <p>if((Session [&quot;A&quot;] != null) &amp;&amp; (Session [&quot;B&quot;] != null)))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Get values from Gridview<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextBoxLenderName.Text = (string)Session[&quot;A&quot;];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextBoxLenderEmail.Text = (string)Session[&quot;B&quot;];</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ChckSBAGuarYes.Checked = (bool)Session[&quot;CKB1&quot;];&nbsp;&nbsp; //NOT WORK<br> &nbsp; </p> <p>&nbsp;&nbsp;&nbsp; }&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2007-08-12T21:35:12-04:001854078http://forums.asp.net/p/1143217/1854078.aspx/1?Re+Getting+values+from+the+Gridview+and+put+it+in+the+previous+form+Re: Getting values from the Gridview and put it in the previous form? <p>Hi:</p> <p>&nbsp; Please try this:</p> <p>Session[&quot;CKB1&quot;] = ((CheckBox)GridView1.Rows[e.NewSelectedIndex].Controls[30].Controls[<strong>index</strong>]).Checked;&nbsp;&nbsp; <strong>//Set a breakpoint here, in watch window, change the index to test. </strong> </p> <p><strong>&nbsp; </strong>A CheckBox will be added to the TableCell if the field is boolean. So you have to find that control and&nbsp;explicitly convert it to CheckBox.</p> <p>Regards</p> 2007-08-13T01:40:49-04:00