Edit in DataGrid

  • Thread starter Thread starter DC
  • Start date Start date
D

DC

Newbie's question about .NET datagrid
If I use:
<asp:EditCommandColumn></asp:EditCommandColumn>
When I edit a row, it will automatically show Update and Cancel Link.

But when I use:
<asp:Button id="btnEdit" runat="server" Text="Edit" CommandName="Edit"
CssClass="clickable"Width="50px" />

When I edit a row, the Update/Cancel links don't show up.

Can someone help me?

This is my code:
<asp:TemplateColumn HeaderText="Action" ItemStyle-Width="120px">
<ItemTemplate>
<asp:Button id="btnEdit" runat="server" Text="Edit"
CommandName="Edit" CssClass="clickable"
Width="50px" />
<asp:Button id="btnDelete" runat="server" Text="Delete"
CommandName="Delete" CssClass="clickable"
Width="50px" />
</ItemTemplate>
</asp:TemplateColumn>


- DC
 
DC said:
Newbie's question about .NET datagrid
If I use:
<asp:EditCommandColumn></asp:EditCommandColumn>
When I edit a row, it will automatically show Update and Cancel Link.

But when I use:
<asp:Button id="btnEdit" runat="server" Text="Edit" CommandName="Edit"
CssClass="clickable"Width="50px" />

When I edit a row, the Update/Cancel links don't show up.

Can someone help me?

This is my code:
<asp:TemplateColumn HeaderText="Action" ItemStyle-Width="120px">
<ItemTemplate>
<asp:Button id="btnEdit" runat="server" Text="Edit"
CommandName="Edit" CssClass="clickable"
Width="50px" />
<asp:Button id="btnDelete" runat="server" Text="Delete"
CommandName="Delete" CssClass="clickable"
Width="50px" />
</ItemTemplate>
</asp:TemplateColumn>

Put the Update and Delete buttons in an EditItemTemplate, not
in an ItemTemplate.
 
Put the Update and Delete buttons in an EditItemTemplate, not
in an ItemTemplate.
Something like this?
<asp:TemplateColumn SortExpression="" HeaderText="Action">
<EditItemTemplate>
<asp:Button id="btnEdit" runat="server" Text="Edit"
CommandName="Edit" CssClass="clickable"
Width="50px" />
<asp:Button id="btnDelete" runat="server" Text="Delete"
CommandName="Delete" CssClass="clickable"
Width="50px" />

</EditItemTemplate>
</asp:TemplateColumn>

The column shows nothing, no buttons at all.
What am I missing?
 
DC said:
Something like this?
<asp:TemplateColumn SortExpression="" HeaderText="Action">
<EditItemTemplate>
<asp:Button id="btnEdit" runat="server" Text="Edit"
CommandName="Edit" CssClass="clickable"
Width="50px" />
<asp:Button id="btnDelete" runat="server" Text="Delete"
CommandName="Delete" CssClass="clickable"
Width="50px" />

</EditItemTemplate>
</asp:TemplateColumn>

The column shows nothing, no buttons at all.
What am I missing?

Dit you handle the EditCommand event on the datagrid?

Something like this:
Sub DataGrid1_OnEditCommand(Sender As Object, E As DataGridCommandEventArgs)
DataGrid1.EditItemIndex = e.Item.ItemIndex
BindGrid()
End Sub

and:

<asp:DataGrid id="DataGrid1" OnEditCommand="DataGrid1_OnEditCommand"
runat="server">
 
Hello,
<asp:editCommandColumn> is in-build feature. So, when you use
this, on edit, you will get other two buttons. If you use
<asp:button>, you will not get buttons for update&calcel. So, you have
to write code on your own for this. <asp:button> is a web control for
buttons to submit pages to server. Similary you can use this for
"Edit", but for update&cancle, you have to write code on your own.

I hope this will help you.

-Sri.
 
Back
Top