Solved

Retrieving Formview ID value with linkbutton

Posted on 2009-07-01
1
589 Views
Last Modified: 2013-12-26
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!
FORMVIEW CONTROL ON ASPX PAGE
 

<asp:FormView ID="FormViewTherapist" runat="server" DataKeyNames="therapistID" DataSourceID="SqlDataSourceTherapistDetail">

<ItemTemplate>

<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" />

</ItemTemplate>

</asp:FormView>
 

CODE BEHIND (VB)
 

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
 

        Me.RepeaterClinicians.DataBind()

        Me.DataListOfficesTherapists.DataBind()

        ID = CInt(ID)

        firstNameAddText = ""

        lastNameAddText = ""
 

    End Sub

Open in new window

0
Comment
Question by:John0214
1 Comment
 

Accepted Solution

by:
John0214 earned 0 total points
ID: 24755676
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!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now