need introduced value in detailsview in code-behind

Discussion in 'ASP .Net' started by bob, Apr 22, 2008.

  1. bob

    bob Guest

    Hi,

    the detailsview (default mode = insert) is used to introduce names into the
    database.
    I need in code-behind the introduced name. I tried this:


    <asp:DetailsView ID="DetailsView1" runat="server" DefaultMode="Insert" >
    <Fields>
    <asp:BoundField DataField="name" />
    <asp:CommandField ShowInsertButton="True" />
    </Fields>
    </asp:DetailsView>


    code-behind:
    -------------
    Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles DetailsView1.DataBound
    dim lol as string
    lol = DetailsView1.Rows(0).Cells(1).Text
    Response.Write(lol)

    End Sub


    but this gives nothing.

    Ant idea how to get the introduced name in code-behind?
    Thanks
    Bob
     
    bob, Apr 22, 2008
    #1
    1. Advertisements

  2. bob

    Manish Guest

    Hi bob,

    I m not able to repplicate the issue. I am getting the desired output. I
    tried the same code that you are using. Please find my aspx page.

    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
    DataKeyNames="CategoryID"
    DataSourceID="SqlDataSource1" Height="50px" Style="position:
    static" Width="125px">
    <Fields>
    <asp:BoundField DataField="CategoryID"
    HeaderText="CategoryID" InsertVisible="False"
    ReadOnly="True" SortExpression="CategoryID" />
    <asp:BoundField DataField="CategoryName"
    HeaderText="CategoryName" SortExpression="CategoryName" />
    <asp:BoundField DataField="Description"
    HeaderText="Description" SortExpression="Description" />
    <asp:CommandField ShowInsertButton="True" />
    </Fields>
    </asp:DetailsView>

    Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles DetailsView1.DataBound
    Dim lol As String
    lol = DetailsView1.Rows(0).Cells(1).Text
    Response.Write(lol)
    End Sub

    I am getting the text from the 1st column in row 0.

    Regards,
    Manish
    www.ComponentOne.com
     
    Manish, Apr 23, 2008
    #2
    1. Advertisements

  3. bob

    Chris Guest

    Thanks for replying, but i still get nothing.
    What do you get?

    i tried this: DetailsView1.Rows(0).Cells(0).Text
    but this gives me the headertext ("name") of the field and not the entered
    value.

    What i want is what the user types into the textbox embedded into the
    detailsview.
    But now i was thinking: is it not to early to use DetailsView1_DataBound,
    because at that stage, nothing is entered into the textbox of the
    detailsview?

    ???
     
    Chris, Apr 24, 2008
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.