Answered by:
New window with link button which displays Gridview row selected in the new window

Question
-
User1717218719 posted
I have a gridview which has varing numbers of row and columns. I have "select" link in my gridview whcih opens up a whole new window The problem I have is I would like to display just the line I have selected in the new window. I have tried various different thing with not much luck. Any help of this would be great.
Code I have in Main aspx.vb:
'--Pop-Up-Window Dim queryString As String = "Popup.aspx" Dim newWin As String = "window.open('" & queryString & "');" ClientScript.RegisterStartupScript(Me.GetType(), "pop", newWin, True)
Code I have in main html:
<asp:GridView CssClass = "gridview" ID="GridView1" runat="server"> <HeaderStyle BackColor = "#507CD1" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor = "#BFE4FF" /> <Columns> <asp:TemplateField HeaderText = " " > <ItemTemplate> <%# Container.DataItemIndex + 1 %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText = " " > <ItemTemplate> <asp:LinkButton CssClass="a" ID="LinkButton3" Text="Select" runat="server" CommandName="Select" CommandArgument="<%# Container.DataItemIndex %>" OnClick="LinkButton3_Click" /> </ItemTemplate> </asp:TemplateField> </Columns> </aspGridView>
Monday, April 29, 2019 11:51 AM
Answers
-
User283571144 posted
Hi E.RU,
According to your description, I still couldn’t understand your requirement clearly.
If you don't want to display the new page by using Gridview, you could use html table control.
You could send the data from mail page to new page by using hyperlink’s query string.
Then you could use request.querystring to get the data in the new page’s page load event, and bind the data to a html table control.
More details, you could refer to below codes:
Main ASPX Page:
<asp:GridView ID="GridView1" runat="server"> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="#BFE4FF" /> <Columns> <asp:TemplateField HeaderText=" "> <ItemTemplate> <asp:HyperLink ID="declare_id" runat="server" Text=' <%#Eval("LoginId") %>' NavigateUrl=' <%# "Popup.aspx?LoginId=" + Eval("LoginId")+"&Name="+Eval("Name")+"&Mail="+Eval("Mail") %>'> </asp:HyperLink> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="HRID" ItemStyle-Width="110px" ItemStyle-CssClass="HRID" DataField="LoginId"> <ItemStyle CssClass="HRID" Width="110px"></ItemStyle> </asp:BoundField> <asp:BoundField HeaderText="Name" ItemStyle-Width="110px" ItemStyle-CssClass="Name" DataField="Name"> <ItemStyle CssClass="Name" Width="110px"></ItemStyle> </asp:BoundField> <asp:BoundField HeaderText="Mail" ItemStyle-Width="110px" ItemStyle-CssClass="Mail" DataField="Mail"> <ItemStyle CssClass="Mail" Width="110px"></ItemStyle> </asp:BoundField> </Columns> </asp:GridView>
New ASPX Page's code behind:
Private Sub SurroundingSub() //Get the parameters passed by the URL Dim LoginId As String = Request.QueryString("LoginId") Dim Name As String = Request.QueryString("Name") Dim Mail As String = Request.QueryString("Mail") //Create header rows Dim trHead As HtmlTableRow = New HtmlTableRow() //Create header cells Dim tcHeadLoginID As HtmlTableCell = New HtmlTableCell() Dim tcHeadName As HtmlTableCell = New HtmlTableCell() Dim tcHeadMail As HtmlTableCell = New HtmlTableCell() //Assign values to header cells tcHeadLoginID.InnerHtml = "LoginId" tcHeadName.InnerHtml = "Name" tcHeadMail.InnerHtml = "Mail" trHead.Cells.Add(tcHeadLoginID) trHead.Cells.Add(tcHeadName) trHead.Cells.Add(tcHeadMail) Table2.Rows.Add(trHead) //Create data rows Dim tr1 As HtmlTableRow = New HtmlTableRow() Dim tc11 As HtmlTableCell = New HtmlTableCell() Dim tc12 As HtmlTableCell = New HtmlTableCell() Dim tc13 As HtmlTableCell = New HtmlTableCell() //Assign values to data cells tc11.InnerHtml = LoginId tc12.InnerHtml = Name tc13.InnerHtml = Mail tr1.Cells.Add(tc11) tr1.Cells.Add(tc12) tr1.Cells.Add(tc13) Table2.Rows.Add(tr1) End Sub
Result:
Best Regards,
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 30, 2019 6:21 AM
All replies
-
User475983607 posted
You have to pass something to the new popup page.
Dim theId As String = "123" Dim queryString As String = "taxPopup.aspx?id=" & theId
Or use a link rather than a linkbutton. With a linkbutton you have to postback then execute JavqaScript. A simple link will be much easier.
Monday, April 29, 2019 12:04 PM -
User1717218719 posted
Thanks for your reply. I found this code for a hyperlink.
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("LeadID") + Request.QueryString("type") %>'Text=""/>
What do I replace "LeadID" an "Type" with ?
Thanks
Monday, April 29, 2019 12:16 PM -
User475983607 posted
Thanks for your reply. I found this code for a hyperlink.
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("LeadID") + Request.QueryString("type") %>'Text=""/>
What do I replace "LeadID" an "Type" with ?
Build a proper URL. Perhaps use string concatenation.
Monday, April 29, 2019 1:08 PM -
User1717218719 posted
Great thanks. The link is now working. I want to display
certain data from my gridview in my main aspx page. How do I do this without recreating a gridview. can I link the two aspx pages?
Monday, April 29, 2019 1:33 PM -
User475983607 posted
Great thanks. The pop up id now working. do I need to still use the code u sent to link the two pages now that I am using a hyperlink?
I have no idea what you are asking. It sounds like the code is working and you are able to pass data in the URL querystring.
Monday, April 29, 2019 1:43 PM -
User1717218719 posted
sorry I edited question
Monday, April 29, 2019 2:04 PM -
User283571144 posted
Hi E.RU,
According to your description, I still couldn’t understand your requirement clearly.
If you don't want to display the new page by using Gridview, you could use html table control.
You could send the data from mail page to new page by using hyperlink’s query string.
Then you could use request.querystring to get the data in the new page’s page load event, and bind the data to a html table control.
More details, you could refer to below codes:
Main ASPX Page:
<asp:GridView ID="GridView1" runat="server"> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="#BFE4FF" /> <Columns> <asp:TemplateField HeaderText=" "> <ItemTemplate> <asp:HyperLink ID="declare_id" runat="server" Text=' <%#Eval("LoginId") %>' NavigateUrl=' <%# "Popup.aspx?LoginId=" + Eval("LoginId")+"&Name="+Eval("Name")+"&Mail="+Eval("Mail") %>'> </asp:HyperLink> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="HRID" ItemStyle-Width="110px" ItemStyle-CssClass="HRID" DataField="LoginId"> <ItemStyle CssClass="HRID" Width="110px"></ItemStyle> </asp:BoundField> <asp:BoundField HeaderText="Name" ItemStyle-Width="110px" ItemStyle-CssClass="Name" DataField="Name"> <ItemStyle CssClass="Name" Width="110px"></ItemStyle> </asp:BoundField> <asp:BoundField HeaderText="Mail" ItemStyle-Width="110px" ItemStyle-CssClass="Mail" DataField="Mail"> <ItemStyle CssClass="Mail" Width="110px"></ItemStyle> </asp:BoundField> </Columns> </asp:GridView>
New ASPX Page's code behind:
Private Sub SurroundingSub() //Get the parameters passed by the URL Dim LoginId As String = Request.QueryString("LoginId") Dim Name As String = Request.QueryString("Name") Dim Mail As String = Request.QueryString("Mail") //Create header rows Dim trHead As HtmlTableRow = New HtmlTableRow() //Create header cells Dim tcHeadLoginID As HtmlTableCell = New HtmlTableCell() Dim tcHeadName As HtmlTableCell = New HtmlTableCell() Dim tcHeadMail As HtmlTableCell = New HtmlTableCell() //Assign values to header cells tcHeadLoginID.InnerHtml = "LoginId" tcHeadName.InnerHtml = "Name" tcHeadMail.InnerHtml = "Mail" trHead.Cells.Add(tcHeadLoginID) trHead.Cells.Add(tcHeadName) trHead.Cells.Add(tcHeadMail) Table2.Rows.Add(trHead) //Create data rows Dim tr1 As HtmlTableRow = New HtmlTableRow() Dim tc11 As HtmlTableCell = New HtmlTableCell() Dim tc12 As HtmlTableCell = New HtmlTableCell() Dim tc13 As HtmlTableCell = New HtmlTableCell() //Assign values to data cells tc11.InnerHtml = LoginId tc12.InnerHtml = Name tc13.InnerHtml = Mail tr1.Cells.Add(tc11) tr1.Cells.Add(tc12) tr1.Cells.Add(tc13) Table2.Rows.Add(tr1) End Sub
Result:
Best Regards,
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 30, 2019 6:21 AM