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

DetailsView cannot get value of textbox

I created a DetailsView along with a GridView.   Everything seems to be working until I get the update.
On the ItemUpdating Event I am trying to get the values of the textboxes to update my sql table.  I have tried several variations of

Dim vLastName = PeopleDetail.FindControl("Last")

Everything errors or returns nothing.  Please help!
0
vzorn
Asked:
vzorn
  • 6
  • 3
  • 2
1 Solution
 
QPRCommented:
what about....

dim vLastname as string = PeopleDetail.FindControl("Last")
Not that I've ever used FindControl, I always just use...

dim vLastName as string = txtboxName.text
0
 
vzornAuthor Commented:
that errors.  it says cannot be converted to a string.
0
 
QPRCommented:
dim vLastName as string = txtboxName.text.ToString() ?
Clutching at straws now. Is there definately a value in the textbox?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
digitalZoCommented:
Try this:
Dim vLastName as TextBox = PeopleDetail.FindControl("Last")
0
 
vzornAuthor Commented:
Dim vLastName as TextBox = PeopleDetail.FindControl("Last") does not error but it comes up as null or blank.  Any suggestions?
0
 
vzornAuthor Commented:
Dim vLastName As String = PeopleDetail.Fields("Last").ToString also does not error but comes up blank
0
 
digitalZoCommented:
Have you given a DataKey? Can you post the code where you're updating?
0
 
vzornAuthor Commented:
Here is the detailsview:

<asp:DetailsView ID="PeopleDetail" runat="server" Height="50px" Width="500px" AutoGenerateRows="False"  CssClass="DataGrid" AutoGenerateEditButton="True"  DataKeyNames="PersonID" BorderColor="Gray" BorderStyle="Solid">
                                            <Fields>
                                                <asp:TemplateField HeaderText="Last Name">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="Last" runat="server" Text='<%# Bind("Last") %>'></asp:TextBox>
                                                    </EditItemTemplate>
                                                    <InsertItemTemplate>
                                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Last") %>'></asp:TextBox>
                                                    </InsertItemTemplate>
                                                    <ControlStyle CssClass="DataGrid" Width="300px" />
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px" />
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Last") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="First" HeaderText="First Name" >
                                                     <ControlStyle CssClass="DataGrid"  Width="300px"/>
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px"/>
                                                    </asp:BoundField>
                                                <asp:BoundField DataField="Middle" HeaderText="Middle Name" >
                                                    <ControlStyle CssClass="DataGrid"  Width="300px"/>
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px"/>
                                                    </asp:BoundField>
                                               
                                                <asp:BoundField DataField="CompanyName" HeaderText="Company" >
                                                    <ControlStyle CssClass="DataGrid"  Width="300px"/>
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px"/>
                                                    </asp:BoundField>
                                                <asp:CheckBoxField DataField="ConfirmedAlias" HeaderText="Confirmed Alias" >
                                                    <ControlStyle CssClass="DataGrid"  Width="300px"/>
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px"/>
                                                    </asp:CheckBoxField>
                                                <asp:BoundField DataField="State" HeaderText="State" >
                                                    <ControlStyle CssClass="DataGrid"  Width="300px"/>
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px"/>
                                                    </asp:BoundField>
                                                <asp:BoundField DataField="DOB" HeaderText="DOB" >
                                                    <ControlStyle CssClass="DataGrid"  Width="300px"/>
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px"/>
                                                    </asp:BoundField>
                                                <asp:BoundField DataField="SSN" HeaderText="SSN" >
                                                    <ControlStyle CssClass="DataGrid"  Width="300px"/>
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px"/>
                                                    </asp:BoundField>
                                                <asp:BoundField DataField="IncorpLLCNumber" HeaderText="Corp No" >
                                                    <ControlStyle CssClass="DataGrid"  Width="300px"/>
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px"/>
                                                    </asp:BoundField>
                                                <asp:BoundField DataField="IncorpDate" HeaderText="Corp Date" >
                                                    <ControlStyle CssClass="DataGrid"  Width="300px"/>
                                                    <HeaderStyle CssClass="DataGridHeader" Width="150px" />
                                                    </asp:BoundField>
                                            </Fields>
                                        </asp:DetailsView>
                                       


This is the beginning of the itemupdating

Private Sub PeopleDetail_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles PeopleDetail.ItemUpdating

        Dim vLastName As String = PeopleDetail.Fields("Last").ToString
        MsgBox(vLastName)

Here is the function that binds the data

 Sub BindPeopleDetail(ByVal vID)
        Dim mtg As ConnectionStringSettings
        mtg = ConfigurationManager.ConnectionStrings("MtgFraud")
        Dim connection As SqlConnection
        connection = New SqlConnection()
        connection.ConnectionString = mtg.ConnectionString
        connection.Open()

        Dim cmd4 As New SqlCommand()
        cmd4 = connection.CreateCommand()
        cmd4.CommandType = CommandType.Text
        cmd4.CommandText = "SELECT PersonID FROM tblLinkPersonScheme WHERE LinkPersonSchemeID = " & vID & ""
        Dim dr4 As SqlDataReader = cmd4.ExecuteReader()
        dr4.Read()
        Dim vPersonID As Integer
        vPersonID = dr4.Item("PersonID").ToString
        dr4.Close()

        Dim cmd5 As New SqlCommand()
        cmd5 = connection.CreateCommand()
        cmd5.CommandType = CommandType.Text
        cmd5.CommandText = "SELECT * FROM tblDataPersons WHERE PersonID = " & vPersonID & ""
        'Dim dr5 As SqlDataReader = cmd5.ExecuteReader()

        Dim adapter As New SqlDataAdapter()

        adapter.SelectCommand = cmd5
        Dim ds = New DataSet
        adapter.Fill(ds, "People")

        PeopleDetail.DataSource = ds.tables("People")
        Dim datakeys As String() = {"PersonID"}

        PeopleDetail.DataKeyNames = datakeys

        PeopleDetail.DataBind()

        connection.Close()
    End Sub
0
 
digitalZoCommented:
You need to reference the Datakey to retrieve the value from the Textbox.

Private Sub PeopleDetail_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles PeopleDetail.ItemUpdating

       Dim personid = DetailsView1.DataKey.Item(0)

        Dim vLastName as TextBox = PeopleDetail.FindControl("Last")
        MsgBox(vLastName)

0
 
vzornAuthor Commented:
I added Dim personid = DetailsView1.DataKey.Item(0)
but it still errors on this:
Dim vLastName As TextBox = PeopleDetail.FindControl("Last")
This is the errror.
Input string was not in a correct format.
0
 
vzornAuthor Commented:
This worked.  Thank you for your help!
Dim vLastName As String = CType(PeopleDetail.FindControl("Last"), TextBox).Text
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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