EditCommandButton in DataGrid

Discussion in 'ASP .Net' started by Steve Black, May 18, 2004.

  1. Steve Black

    Steve Black Guest

    Hello,

    I am trying to add an EditCommand Button to a datagrid. If I
    programmatically add the button, like this:

    Dim eb As EditCommandColumn

    eb = New EditCommandColumn
    With eb
    .ButtonType = ButtonColumnType.PushButton
    .EditText = "Edit"
    .UpdateText = "Update"
    .CancelText = "Cancel"
    .ItemStyle.HorizontalAlign = HorizontalAlign.Center
    .HeaderStyle.BorderStyle = BorderStyle.None
    End With

    prmDataGrid.Columns.Add(eb)


    I have no problems at all.

    However, if I simply add a static button at design time, like this:

    <Columns>
    <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update"
    CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>

    ....other columns here...
    </Columns>

    Then when I actually click my Edit button, my code-behind doesn't
    fire. I am not altering my datagrid as all. My datagrid control
    looks like this:

    <asp:datagrid Width="75%" id="dgTest" runat="server"
    GridLines="Horizontal" AutoGenerateColumns="False"
    OnEditCommand="dgTest_EditCommand">
    <HeaderStyle CssClass="MinorTitles"></HeaderStyle>
    <Columns>
    ....
    </Columns>
    </asp:datagrid>

    I'm not sure why my function 'dgTest_EditCommand' will work if I
    programmatically add the EditCommandButton but will not work when I
    use a static button.

    Any ideas?

    Thanks,

    Steve
     
    Steve Black, May 18, 2004
    #1
    1. Advertising

  2. Steve Black

    Cowboy Guest

    When you place it in the ASP, it does not automagically wire up necessarily
    (I think it does if you use the right click "Property Builder", but I have
    not tested. To manually wire it up, create the event handler(s) you need and
    add Handles EventName to the end. That should solve the problem.

    Occasionally, VS.NET will delete handlers (not sure what the cause is), so
    getting the Handles syntax down is a godsend.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    ************************************************
    Think Outside the Box!
    ************************************************
    "Steve Black" <> wrote in message
    news:...
    > Hello,
    >
    > I am trying to add an EditCommand Button to a datagrid. If I
    > programmatically add the button, like this:
    >
    > Dim eb As EditCommandColumn
    >
    > eb = New EditCommandColumn
    > With eb
    > .ButtonType = ButtonColumnType.PushButton
    > .EditText = "Edit"
    > .UpdateText = "Update"
    > .CancelText = "Cancel"
    > .ItemStyle.HorizontalAlign = HorizontalAlign.Center
    > .HeaderStyle.BorderStyle = BorderStyle.None
    > End With
    >
    > prmDataGrid.Columns.Add(eb)
    >
    >
    > I have no problems at all.
    >
    > However, if I simply add a static button at design time, like this:
    >
    > <Columns>
    > <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update"
    > CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
    >
    > ...other columns here...
    > </Columns>
    >
    > Then when I actually click my Edit button, my code-behind doesn't
    > fire. I am not altering my datagrid as all. My datagrid control
    > looks like this:
    >
    > <asp:datagrid Width="75%" id="dgTest" runat="server"
    > GridLines="Horizontal" AutoGenerateColumns="False"
    > OnEditCommand="dgTest_EditCommand">
    > <HeaderStyle CssClass="MinorTitles"></HeaderStyle>
    > <Columns>
    > ...
    > </Columns>
    > </asp:datagrid>
    >
    > I'm not sure why my function 'dgTest_EditCommand' will work if I
    > programmatically add the EditCommandButton but will not work when I
    > use a static button.
    >
    > Any ideas?
    >
    > Thanks,
    >
    > Steve
     
    Cowboy, May 18, 2004
    #2
    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. Dave
    Replies:
    0
    Views:
    474
  2. BK Kim

    datagrid in datagrid

    BK Kim, Feb 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    569
    Alvin Bruney [MVP]
    Mar 2, 2004
  3. =?Utf-8?B?U3VyZXNo?=
    Replies:
    0
    Views:
    546
    =?Utf-8?B?U3VyZXNo?=
    Mar 2, 2004
  4. Brian K. Williams
    Replies:
    0
    Views:
    561
    Brian K. Williams
    Mar 2, 2004
  5. Andreas Klemt
    Replies:
    0
    Views:
    333
    Andreas Klemt
    Oct 8, 2003
Loading...

Share This Page