• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

How to pass value from gridview to another page

Hi,

I am new and using appended gridview to display data. I need to convert Inv Number column in hyperlink and send its text to another page "~/InvPageAdd.aspx".

Please help

  <asp:HyperLinkField DataTextField="InvNo" HeaderText="Inv Number" />
 
gridview
0
Mehram
Asked:
Mehram
  • 3
  • 3
1 Solution
 
Julian HansenCommented:
Does this help

<asp:HyperLinkField DataNavigateUrlFields="InvNo"
DataNavigateUrlFormatString="InvPageAdd.aspx?inv={0}" DataTextField="InvNo" HeaderText="Inv Number"/>

Open in new window

0
 
MehramAuthor Commented:
showing error on data binding:

error
0
 
Julian HansenCommented:
Can you show your code where you have put the hyperlink def in?

Usually you get this error when the type conversion of the parameter you are putting in the link is incorrect.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
MehramAuthor Commented:
<Columns>
    <asp:BoundField DataField="Sno" HeaderText="Serial #" />
    <asp:BoundField DataField="Date" HeaderText="Inv Date" />
    <asp:BoundField DataField="InvNo" HeaderText="Inv Number" />
    <asp:BoundField DataField="Amt" HeaderText="Amount" />
    <asp:BoundField DataField="CoCom" HeaderText="Co Comm"/>
    <asp:BoundField DataField="MkCom" HeaderText="Mk Comm"/>
    <asp:BoundField DataField="NPV" HeaderText="Net Inv Value" ItemStyle-HorizontalAlign="Center">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    </asp:BoundField>
    <asp:CheckBoxField DataField="FreeStock" HeaderText="Free Stock"/>
    <asp:HyperLinkField DataNavigateUrlFields="InvNo" DataNavigateUrlFormatString="InvPageAdd.aspx?InvNo={8}" Text="Edit" HeaderText="Inv Number"/>
    </Columns>
0
 
MehramAuthor Commented:
Sir,
I did something like this, which is working: please guide me if I can enhance it?


    <Columns>
    <asp:BoundField DataField="Sno" HeaderText="Serial #" />
    <asp:BoundField DataField="Date" HeaderText="Inv Date" />
    <asp:TemplateField>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Invoice #">
    <ItemTemplate>
    <asp:LinkButton ID="lnkname" runat="server"
                Text=<%#Eval("InvNo") %>'
                PostBackUrl='<%#"~/InvPageAdd.aspx?ID="+Eval("InvNo")%>'>
    </asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="Amt" HeaderText="Amount" />
    <asp:BoundField DataField="CoCom" HeaderText="Co Comm"/>
    <asp:BoundField DataField="MkCom" HeaderText="Mk Comm"/>
    <asp:BoundField DataField="NPV" HeaderText="Net Inv Value" ItemStyle-HorizontalAlign="Center">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    </asp:BoundField>
    <asp:CheckBoxField DataField="FreeStock" HeaderText="Free Stock"/>
    </Columns>
0
 
Julian HansenCommented:
Change this line
<asp:HyperLinkField DataNavigateUrlFields="InvNo" DataNavigateUrlFormatString="InvPageAdd.aspx?InvNo={8}" Text="Edit" HeaderText="Inv Number"/>

Open in new window

to (the {8} => {0} also can try with ~/ infront of url
<asp:HyperLinkField DataNavigateUrlFields="InvNo" DataNavigateUrlFormatString="~/InvPageAdd.aspx?InvNo={0}" Text="Edit" HeaderText="Inv Number"/>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now