GridView1_RowCreated versus GridView1_RowDataBound

Discussion in 'ASP .Net' started by Ben, Jun 13, 2008.

  1. Ben

    Ben Guest

    Hi,

    i'm a little bit confused about the events GridView1_RowDataBound and
    GridView1_RowCreated.

    1) Which is executed first?
    2) if i want to fetch the value of a field using this code:
    dim a as string
    a = e.Row.Cells(2).Text

    in which event do i have to do that?

    3) there is a dropdownlist in aspx file embebbed in a template like this:
    <asp:TemplateField >
    <EditItemTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server" >
    </asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateField>

    i want to access it with this code:
    dim dd as dropdownlist
    dd = e.Row.FindControl("DropDownList1")

    in which event do i have to do that?

    Thanks
    Bob
     
    Ben, Jun 13, 2008
    #1
    1. Advertisements

  2. Ben

    Munna Guest

    Hi

    "1) Which is executed first? .."

    rowcreated is execute first... then rowdatabound....

    "2) if i want to fetch the value of a field using this code: ... in
    which event do i have to do that? "

    RowDataBound


    3) there is a dropdownlist in aspx file embebbed in a template like
    this: ....in which event do i have to do that?

    RowDataBound

    Thanks

    Munna
     
    Munna, Jun 13, 2008
    #2
    1. Advertisements

  3. Ben

    Ben Guest

    ok, thanks
     
    Ben, Jun 13, 2008
    #3
  4. Ben

    Ben Guest

    Hi again,

    i posted this but no answer, and because it has to do with this topic, maybe
    you can solve this:

    Can someone explain me why the same code with the event
    GridView1_RowDataBound gives this error:

    'DropDownList1' has a SelectedValue which is invalid because it does not
    exist in the list of items.
    Parameter name: value

    and not with the event GridView1_RowCreated ?

    Thanks
    Ben

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As

    System.Web.UI.WebControls.GridViewRowEventArgs) Handles
    GridView1.RowDataBound
    If (e.Row.RowState And DataControlRowState.Edit) =
    DataControlRowState.Edit Then
    If e.Row.RowType = DataControlRowType.DataRow Then
    Dim dd As DropDownList
    Dim i As Integer
    Dim z As ListItem
    dd = e.Row.FindControl("DropDownList1")
    For i = 1 To 20
    z = New ListItem(i, i)
    dd.Items.Add(z)
    Next
    End If
    End If
    End Sub
     
    Ben, Jun 14, 2008
    #4
    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.