Pass Parameter As DataGridItemEventArgs

Discussion in 'ASP .Net' started by rn5a@rediffmail.com, Dec 2, 2006.

  1. Guest

    A Form has a DataGrid & a Button. The DataGrid's ItemDataBound event
    calls a sub named 'BindData'. This sub first finds a Label which exists
    in the ItemTemplate of the TemplateColumn of the DataGrid & does some
    work with the Label.

    Sub BindData(obj As Object, ea As DataGridItemEventArgs)
    Dim lbl As Label

    If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
    ListItemType.AlternatingItem) Then
    lbl = ea.Item.FindControl("lblAcre")
    .....
    .....
    End If
    End Sub

    The Button has the Click event which invokes a sub named 'SubmitPage'.

    Sub SubmitPage(obj As Object, ea As EventArgs)
    .....
    End Sub

    Now I did like the 'SubmitPage' sub to invoke the 'BindData' sub. How
    do I accomplish this? In other words, what parameters do I pass from
    the 'SubmitPage' sub to the 'BindData' sub which the latter expects?
    , Dec 2, 2006
    #1
    1. Advertising

  2. Teemu Keiski Guest

    You can't get DataGridItemEventArgs in SubmitPage (it is event argument data
    type specific to a event, so it's not even wise to use as input to a
    method), but you can loop through the DataGrid manually.

    Sub SubmitPage(obj As Object, ea As EventArgs)


    For each dgitem As DataGridItem in DataGrid1.Items

    Dim lbl As Label=Nothing

    If (dgitem.ItemType = ListItemType.Item Or dgitem.ItemType =
    ListItemType.AlternatingItem) Then
    lbl = dgitem.FindControl("lblAcre")
    'Do something with the Label
    End If

    Next

    End Sub


    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    <> wrote in message
    news:...
    >A Form has a DataGrid & a Button. The DataGrid's ItemDataBound event
    > calls a sub named 'BindData'. This sub first finds a Label which exists
    > in the ItemTemplate of the TemplateColumn of the DataGrid & does some
    > work with the Label.
    >
    > Sub BindData(obj As Object, ea As DataGridItemEventArgs)
    > Dim lbl As Label
    >
    > If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
    > ListItemType.AlternatingItem) Then
    > lbl = ea.Item.FindControl("lblAcre")
    > .....
    > .....
    > End If
    > End Sub
    >
    > The Button has the Click event which invokes a sub named 'SubmitPage'.
    >
    > Sub SubmitPage(obj As Object, ea As EventArgs)
    > .....
    > End Sub
    >
    > Now I did like the 'SubmitPage' sub to invoke the 'BindData' sub. How
    > do I accomplish this? In other words, what parameters do I pass from
    > the 'SubmitPage' sub to the 'BindData' sub which the latter expects?
    >
    Teemu Keiski, Dec 2, 2006
    #2
    1. Advertising

  3. Guest

    Thanks, Teemu....that's exactly what I was looking out for


    Teemu Keiski wrote:
    > You can't get DataGridItemEventArgs in SubmitPage (it is event argument data
    > type specific to a event, so it's not even wise to use as input to a
    > method), but you can loop through the DataGrid manually.
    >
    > Sub SubmitPage(obj As Object, ea As EventArgs)
    >
    >
    > For each dgitem As DataGridItem in DataGrid1.Items
    >
    > Dim lbl As Label=Nothing
    >
    > If (dgitem.ItemType = ListItemType.Item Or dgitem.ItemType =
    > ListItemType.AlternatingItem) Then
    > lbl = dgitem.FindControl("lblAcre")
    > 'Do something with the Label
    > End If
    >
    > Next
    >
    > End Sub
    >
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    > <> wrote in message
    > news:...
    > >A Form has a DataGrid & a Button. The DataGrid's ItemDataBound event
    > > calls a sub named 'BindData'. This sub first finds a Label which exists
    > > in the ItemTemplate of the TemplateColumn of the DataGrid & does some
    > > work with the Label.
    > >
    > > Sub BindData(obj As Object, ea As DataGridItemEventArgs)
    > > Dim lbl As Label
    > >
    > > If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
    > > ListItemType.AlternatingItem) Then
    > > lbl = ea.Item.FindControl("lblAcre")
    > > .....
    > > .....
    > > End If
    > > End Sub
    > >
    > > The Button has the Click event which invokes a sub named 'SubmitPage'.
    > >
    > > Sub SubmitPage(obj As Object, ea As EventArgs)
    > > .....
    > > End Sub
    > >
    > > Now I did like the 'SubmitPage' sub to invoke the 'BindData' sub. How
    > > do I accomplish this? In other words, what parameters do I pass from
    > > the 'SubmitPage' sub to the 'BindData' sub which the latter expects?
    > >
    , Dec 2, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hajime Kusakabe
    Replies:
    1
    Views:
    573
    Mike Moore [MSFT]
    Oct 23, 2003
  2. Jerry
    Replies:
    20
    Views:
    7,899
    Roedy Green
    Sep 9, 2005
  3. =?Utf-8?B?U3Vl?=
    Replies:
    2
    Views:
    1,167
    =?Utf-8?B?U3Vl?=
    Jun 26, 2006
  4. =?Utf-8?B?UGF1bA==?=

    DataGridItemEventArgs and Hyperlinkcolumn

    =?Utf-8?B?UGF1bA==?=, Aug 15, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    650
    PeterKellner
    Aug 15, 2006
  5. AzamSharp
    Replies:
    2
    Views:
    163
Loading...

Share This Page