Hi localhost,
Welcome to use Microsoft Newsgroup Service. Based on your problem
description, you want to add a bttton(in a column) into a DataGrid and the
button only shows on the row which is under edit mode, is my understanding
correct?
If so, here is my suggestion:
As you said that "It is fine to display the new column for every row,, but
not a delete button for the rows that are not being edited", yes, we do can
add a new column with a button and the button only shows when the row is
under edit mode.
We can use a Template column such as(I specify all the columns in aspx
file, not use AutoGenerateCol umns, I think this way is better):
<asp:datagrid id=gridTest runat="server" AutoGenerateCol umns="False">
<Columns>
............... .//other columns here
<asp:TemplateCo lumn>
//let the ItemTemplate empty so that nothing will display when the row is
not in edit mode(also you can put some other thins //such as a label, text
,etc...)
<ItemTemplate > </ItemTemplate>
//put a serverside button in the EditItemTemplat e so that the button will
show when the row is being edited
<EditItemTempla te>
<asp:Button ID="delete" Text="delete" Runat="server"
CommandName="de leterow"></asp:Button>
</EditItemTemplat e>
</asp:TemplateCol umn>
</Columns>
</asp:datagrid>
#notice that the <asp:Button> has a CommandName="de leterow", we must set
this attribute so that we can get the button's click event in the
DataGrid's ItemCommand Event handler. For example: choose the
DataGrid(gridTe st)'s ItemCommand handler:
private void gridTest_ItemCo mmand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
if(e.CommandNam e.Equals("delet erow")
{
//add your operation code here
}
}
There are two key points, 1) is that use a Template column, and set its
"EditItemTempla te" with a button, the "ItemTempla te without the button"
2) we should capture the button's click event in the DataGrid's
"ItemComman d" event and determind whether the button is clicked by the
"CommandNam e" attribute of the
"System.Web.UI. WebControls.Dat aGridCommandEve ntArgs e".
Please try out my suggestions. If you have any questions on it, please feel
free to let me know.
BTW localhost, since the notify-mail I sent you always returned fail
message said that the mail address "pr*******@coho rt.ces" is unreachable,
would you please have a check on the mail address? Thus, we can send you
the latest update in time, and here is the weblink where you can change
your email setting of the newsgroup :
http://support.microsoft.com/default...sdn/nospam.asp
&SD=msdn
Thanks.
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)