SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to get Value from ItemTemplate in Gridview

    I am using the Invoice Id number as a Hyperlink in the gridview ItemTemplate column. I need to get that number when the user checks the checkbox of that row. Problem getting the value of that Hyperlink, which is the invoice id, that I need to complete the C# code. I not understanding how to get the value of the Hyperlink control. I see the code will get me the control itself, but no idea how to get the value of the control.

    Code Csharp:
     for (int i = 0; i < gv_ebill.Rows.Count; i++)
            {
                GridViewRow row = gv_ebill.Rows[i];
                bool isChecked = ((CheckBox)row.FindControl("ck_ebill")).Checked;
     
                if (isChecked)
                {
     
    // trying to get the invoiceid from the row
    int invoiceid = row.FindControl("invoiceId").
     
                    invoice = new Invoice(Convert.ToInt32(row.Cells[1].Text), currentClient.Practice.Id);



    [
    Code ASP:
    <asp:TemplateField HeaderText = "Id" SortExpression="id">
                    <ItemTemplate>
                    <asp:HyperLink 
                            ID="invoiceId" runat="server" NavigateUrl='~/Invoice_Overview.aspx?Id=<%# Eval("Id") %>' ><%# Eval("Id") %></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>

  2. #2
    SitePoint Wizard webcosmo's Avatar
    Join Date
    Oct 2007
    Location
    Boston, MA
    Posts
    1,480
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Not sure what you mean by value.
    You can get a reference to the control like this
    HyperLink hl=(HyperLink)row.FindControl("invoiceId");

    then you can use hl to get different aspects of it.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a column with Invoice Id's like '99009' and it is a hyperlink to let the user look at the invoice. But I need to get the '99009' into my C# code to use it in the program. I can't detect how to get the Hyperlink value as an Int in C#.

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,629
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Int32.Parse() is magic.

  5. #5
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,877
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    As wwb said. You need to parse / convert your hyperlinks text value into and int. Like he suggested above or using Convert.ToInt32(string value);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •