EditCommandButton in DataGrid

  • Thread starter Thread starter Steve Black
  • Start date Start date
S

Steve Black

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
 
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!
************************************************
 
Back
Top