Improve company productivity with a Business Account.Sign Up

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

Retrieving Formview ID value with linkbutton

Hello - I am attempting to insert the ID from a Formview into the ID column of a datatable using a linkbutton. I am able to insert the firstName and lastName, but the ID is coming over as zero (0).

I'm not sure that my coding is correct for this, as it's the first time I've attempted this with a formview control. Specifically, I don't know if I'm using the linkbutton's CommandArgument and OnCommand correctly.

I have OnCommand equal to the code-behind Sub. And I have the CommandArgument equal to the ID (using Eval).

In the code-behind I am declaring the ID like this:
Dim ID As Integer = FormViewTherapist.DataKey(e.CommandArgument)

Again, I'm not sure if this is correct. I'm getting zero for the value instead of the true ID.

Thanks for your help!
<asp:FormView ID="FormViewTherapist" runat="server" DataKeyNames="therapistID" DataSourceID="SqlDataSourceTherapistDetail">
<asp:LinkButton ID="LinkButton1" runat="server" CssClass="selectlink" OnCommand="AddToClinicianListFromClinician" CommandArgument='<%# Eval("therapistID") %>'>Add to Selection</asp:LinkButton>
<asp:Label ID="firstNameLabel" runat="server" Text='<%# Bind("firstName") %>' CssClass="big" />
<asp:Label ID="lastNameLabel" runat="server" Text='<%# Bind("lastName") %>' CssClass="big" />
Dim ID As Integer = FormViewTherapist.DataKey(e.CommandArgument)
        Dim firstNameAdd As Label = CType(FormViewTherapist.Row.FindControl("firstNameLabel"), Label)
        Dim lastNameAdd As Label = CType(FormViewTherapist.Row.FindControl("lastNameLabel"), Label)
        Dim firstNameAddText As String = firstNameAdd.Text
        Dim lastNameAddText As String = lastNameAdd.Text
        AddClinicianTable(ID, firstNameAddText, lastNameAddText, CType(Session("CliniciansTableSession"), DataTable))
        Me.RepeaterClinicians.DataSource = CType(Session("CliniciansTableSession"), DataTable).DefaultView
        ID = CInt(ID)
        firstNameAddText = ""
        lastNameAddText = ""
    End Sub

Open in new window

1 Solution
John0214Author Commented:
Nevermind - I figured it out.

The code-behind should be:
Dim ID As Integer = e.CommandArgument

I'm starting to get the hang of this. Scary!
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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