how to get the value of a non key field in RowCommand event?

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

  1. Ben

    Ben Guest

    Hi,

    i know how to get the value of the key field in code-behind, but not how to
    get the value of a non key field:

    aspx file:
    --------
    <asp:GridView ID="GridView1" runat="server" DataKeyNames="id"
    DataSourceID="SqlDataSource1" >
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:LinkButton ID="lb1" runat="server" CommandArgument="<%#
    Container.DataItemIndex %>" CommandName="Delete">
    </asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    ....
    </asp:GridView>

    code-behind:
    --------------
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
    GridView1.RowCommand

    Dim r As Integer = Convert.ToInt32(e.CommandArgument)
    Dim dbkey As String
    dbkey = GridView1.DataKeys(r).Value
    If e.CommandName = "Delete" Then
    .....
    Me.SqlDataSource1.DeleteCommand = "delete from mytable where id= '"
    & dbkey & "'"
    ......

    This works. But how to get the value of a non key field (call it 'myfield')
    in order to perform other actions with it.

    Thanks
    Ben
     
    Ben, Jun 11, 2008
    #1
    1. Advertising

  2. Ben

    Munna Guest

    Hi

    check out this code

    Dim r As Integer = Convert.ToInt32(e.CommandArgument)
    Dim dbkey As String
    dbkey = GridView1.DataKeys(r).Value
    Dim fieldValue As String

    'used the r to key row and access the cells

    fieldValue = GridView1.Rows(r).Cells(0).Text

    Best of luck

    Munna
     
    Munna, Jun 11, 2008
    #2
    1. Advertising

  3. Ben

    Ben Guest

    thank you very much

    "Munna" <> schreef in bericht
    news:...
    > Hi
    >
    > check out this code
    >
    > Dim r As Integer = Convert.ToInt32(e.CommandArgument)
    > Dim dbkey As String
    > dbkey = GridView1.DataKeys(r).Value
    > Dim fieldValue As String
    >
    > 'used the r to key row and access the cells
    >
    > fieldValue = GridView1.Rows(r).Cells(0).Text
    >
    > Best of luck
    >
    > Munna
     
    Ben, Jun 11, 2008
    #3
  4. Ben

    Munna Guest

    On Jun 12, 12:03 am, "Ben" <> wrote:
    > thank you very much
    >
    > "Munna" <> schreef in berichtnews:...
    >
    > > Hi

    >
    > > check out this code

    >
    > > Dim r As Integer = Convert.ToInt32(e.CommandArgument)
    > > Dim dbkey As String
    > > dbkey = GridView1.DataKeys(r).Value
    > > Dim fieldValue As String

    >
    > > 'used the r to key row and access the cells

    >
    > > fieldValue = GridView1.Rows(r).Cells(0).Text

    >
    > > Best of luck

    >
    > > Munna


    Glad to help you...

    best of luck

    Munna
     
    Munna, Jun 11, 2008
    #4
    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. keithb
    Replies:
    1
    Views:
    4,330
    PeterKellner
    Jun 10, 2006
  2. Kevin Attard

    GridView RowCommand event not firing!!

    Kevin Attard, Aug 8, 2006, in forum: ASP .Net
    Replies:
    8
    Views:
    31,752
    Lawrence Mucheka
    May 29, 2008
  3. slayer35
    Replies:
    0
    Views:
    2,550
    slayer35
    Aug 12, 2006
  4. =?Utf-8?B?cGF0cmlja2RyZA==?=

    gridview inside datagrid doen't raise RowCommand event

    =?Utf-8?B?cGF0cmlja2RyZA==?=, Apr 3, 2007, in forum: ASP .Net
    Replies:
    7
    Views:
    2,686
    =?Utf-8?B?cGF0cmlja2RyZA==?=
    Apr 4, 2007
  5. jr
    Replies:
    3
    Views:
    451
Loading...

Share This Page