473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

DataGrid Add single row/column?

When I go into Edit mode on a datagrid, I would like to
add a single column to the edited row and display a
hyperlink. If I use the code below, I get a delete
linkbutton in every row, when I only want it for the row
I am editing. It is fine to display the new column for
every row, but not a delete button for the rows that are
not being edited.

System.Web.UI.WebControls.ButtonColumn dc = new
ButtonColumn();
dc.ButtonType =
System.Web.UI.WebControls.ButtonColumnType.LinkBut ton;
dc.HeaderText = "Delete";
dc.Text = "[Del]";
dc.CommandName = "DeleteRow";
myGrid.Columns.Add( dc );
Thanks.

Nov 18 '05 #1
2 2048
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 AutoGenerateColumns, I think this way is better):

<asp:datagrid id=gridTest runat="server" AutoGenerateColumns="False">
<Columns>
................//other columns here

<asp:TemplateColumn>
//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 EditItemTemplate so that the button will
show when the row is being edited
<EditItemTemplate>
<asp:Button ID="delete" Text="delete" Runat="server"
CommandName="deleterow"></asp:Button>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

#notice that the <asp:Button> has a CommandName="deleterow", 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(gridTest)'s ItemCommand handler:

private void gridTest_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName.Equals("deleterow")
{
//add your operation code here
}
}

There are two key points, 1) is that use a Template column, and set its
"EditItemTemplate" with a button, the "ItemTemplate without the button"
2) we should capture the button's click event in the DataGrid's
"ItemCommand" event and determind whether the button is clicked by the
"CommandName" attribute of the
"System.Web.UI.WebControls.DataGridCommandEventArg s 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*******@cohort.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.)

Nov 18 '05 #2
Hi localhost,

Have you had a chance to try out my suggestion or have you resolved your
problem? Please let me know if you need
any help.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
3
by: Doug | last post by:
Hi I have the following code (not mine) that populates a datagrid with some file names. But I want to replace the datagrid with a combo box. private void OnCurrentDataCellChanged(object sender,...
2
by: martin | last post by:
Hi, I am iterating through the dataitems in a datagrid and producing and xml document, If a particular cell in the datagrid has a textbox control or a datagrid control in it then I have no...
0
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
6
by: Agnes | last post by:
I understand it is impossible, but still curious to know "Can I freeze several column in the datagrid, the user can only scroll the first 3 columns (not verical), for the rest of the coulumn, it is...
5
by: Bruce D | last post by:
Is there a way to programatically set the format of just one column in a datagrid? I have a datagrid bined to a datasource. My dataview has 6 columns. And I want to format one column...
2
by: cj | last post by:
I was looking over some of my 2003 code today (see below) that loads a foxpro table via oledb connection. I used a sub "autosizecolumns" I found on the web but I never quite understood why they...
1
by: yumbelie | last post by:
Hi, I want to set multiple datafields from a dataset to a single boundcolumn in my gridview, but I can't see any easy way to do this since the DataField property of the boundcolumn takes a single...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.