473,569 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.W ebControls.Butt onColumn dc = new
ButtonColumn();
dc.ButtonType =
System.Web.UI.W ebControls.Butt onColumnType.Li nkButton;
dc.HeaderText = "Delete";
dc.Text = "[Del]";
dc.CommandName = "DeleteRow" ;
myGrid.Columns. Add( dc );
Thanks.

Nov 18 '05 #1
2 2055
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.)

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
7896
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 header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the...
2
9911
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 (multi-select without modifier keys). I got that working fine, but I also wanted to keep rows selected after a sort, which I do by storing the row's...
3
2990
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, System.EventArgs e) {try{ DataSet ds = dgMembers.DataSource as DataSet;
2
1578
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 problem retrieveing it value by casting with CTYPE however when the datagrid cell contains no control, but does contain text, then I am having great...
0
1688
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 single worksheet into a dataset. I successfully built a dynamic datagrid. And I did successfully bind it to the dataset. Then I added the datagrid...
2
6384
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
2738
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 freeze.
5
1725
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 ('amount')...without have to mess with all the other columns. If I use DataGridTableStyle() and DataGridTextBoxColumn() (see following code)...my datagrid...
2
1767
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 said the style name had to be the same as the table name. Perhaps the are refering to ts1.mappingname must be the same as the table name...
1
4601
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 string that maps 1-to-1 to the relevant column in the dataset. I want to map three columns from my dataset to a single column in my DataGrid - is there...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.