473,695 Members | 2,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem while removing row Dynamically from datagrid

Hello All,

I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically added row it also removes the row at the end along with the added row.

Plz tell me if, I am missing any thing.

Code[*]

</asp:datagrid>

Asp Code==>

<asp:datagrid id="PartGrid" Runat="server" AutoGenerateCol umns="False" AllowPaging="Tr ue" ageSize="10">

<Columns>

<asp:TemplateCo lumn>

<ItemTemplate >

<asp:LinkButt on id="btnDetail" Runat="server" CommandName="Ex pand">+</asp:LinkButton>

</ItemTemplate>

</asp:TemplateCol umn>

<asp:BoundColum n DataField="part Name" HeaderText="Par t Name" />

<asp:BoundColum n DataField="part Type" HeaderText="Par t Type" />

<asp:BoundColum n DataField="stat us" HeaderText="Sta tus" />

</Columns>

</asp:datagrid>

Code behind file (1) In the Item created event adding the Click event handler for the button

private void PartGrid_ItemCr eated(object sender, System.Web.UI.W ebControls.Data GridItemEventAr gs e)

{

ListItemType eItemtype = e.Item.ItemType ;

if ( eItemtype == ListItemType.Al ternatingItem || eItemtype == ListItemType.It em)

{

btnDetail = e.Item.FindCont rol("btnDetail" ) as LinkButton;

btnDetail.Click += new EventHandler(bt nDetail_Click);

}

}

(2)On click event Adding the new new row . In this event handler Adding the row if Button text is "+" else

I am trying to remove it. The Adding functionality working fine but while removing, it is also removing the extra row at the end. plz help me out.

private void btnDetail_Click (object sender, EventArgs e)

{

LinkButton btnTemp = sender as LinkButton;

if(btnTemp.Text == "+")

{

btnTemp.Text = "-";

DataGridItem item = (DataGridItem)( (LinkButton)sen der).NamingCont ainer; //Getting the container row

int rowIndex = ((Table)(PartGr id.Controls[0])).Rows.GetRowI ndex((TableRow) item);//its row index

DataGridItem dgRow = new DataGridItem(ro wIndex + 1, 0, ListItemType.It em); //new Datagrid row
TableCell cell = new TableCell();

cell.ColumnSpan = item.Cells.Coun t;

cell.Controls.A dd(new Label());

dgRow.Cells.Add (cell);

((Table)(PartGr id.Controls[0])).Rows.AddAt(r owIndex + 1, dgRow);

}

else

{

btnTemp.Text = "+";

DataGridItem item = (DataGridItem)( (LinkButton)sen der).NamingCont ainer;

int rowIndex = ((Table)(PartGr id.Controls[0])).Rows.GetRowI ndex((TableRow) item);

((Table)(PartGr id.Controls[0])).Rows.RemoveA t(rowIndex + 1);

}

}

Thanks in Advance

Sameer

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>VFXa6qEAtkS lvcAKrcX1OA==</Id>
Nov 17 '05 #1
0 2468

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

Similar topics

3
3346
by: Shravan Kumar | last post by:
Hi, I am using my code to set column widths of datagrid columns dynamically, but when I am setting the column widths to zero, the header text of the column whose width is made to zero is appearing on the existing column headers, and the text gets blurred with the painting of the column text along with the adjacent width 0 column. Anybody, can you please give me a solution for it
2
3900
by: Dave Bailey | last post by:
I am trying to dynamically build a DataGrid dynamically. The code runs OK but the DataGrid is never built and displayed. Can someone look at the following code and see if they can determine what I am missing. Thanks, Dave using System;
4
2120
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated Datagrid in a Web Custom Control (WCC) : The datagrid has LinkButton Column which has a select LinkButton for each row. When this button is clicked, the Datagrid raises its 'ItemCommand' event which captures the information for that row and...
7
3341
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question, Ive implemented the drop down menu as a drop down list instead. Ive got all this working at this...
66
4120
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It started by an example from me, that was far from complete and with typing errors, but basically it had the meaning to show that removing controls reversible was the nicest method. This was a lets say conclusion (but what is that in a newsgroup) in a...
0
1346
by: news.zen.co.uk | last post by:
Hi Guys, Using VB .NET 2003 and ASP1.1, I have a Datagrid embedded in an ASP page. In the processing of the ItemDataBound event I dynamically create a new Datagrid control within the Cell of the Parent (this refelect GUI'wise a Parent Child related data). I also add Handlers to the sub datagrid using AddHandler to handle the EditCommandColumn as well as ItemDataBound. Parent Datagrid...
4
2127
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a Delete button on the end of each row. I am unable to gain access to the event when the button is clicked. I don't fully understand how the click gets connected to the C# code,
4
5047
by: sydney.luu | last post by:
Hello, I would greatly appreciate if someone can show me how to dynamically build a Repeater with unknown number of columns at design time. I have looked various threads in this newsgroup, websites, MSDN and was not able to find something that would help me understand and code. I might not be searching for the right words or phrases. So if you know how to do this or know of links or websites that have information about this, please...
3
4362
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If condition1 is true, then the SqlDataReader will be populated with the records existing in table1 & will return 0 to the calling function but if condition2 is true, then the SqlDataReader will be populated with the records from another table named...
0
8572
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9115
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8984
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8847
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8825
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7661
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6491
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4340
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3003
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.