473,789 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remove row from datagrid dynamicly

I have a datagrid where a user can edit a number in one of the columns for a
quantity value. On the postback I loop through all of the datagrid items
and if the quantity has changed, then I update the value of the extended
price cell for that datagrid item.

Also, the datagrid has a checkbox in each row called "Remove" where if the
checkbox is checked I delete that row from the underlying datasource and set
a flag which tells me to rebind the datagrid before the page sent back to
the client. Rather that raising a flag and rebinding the datagrid, I was
hoping I could simply remove that datagrid item (row) as I'm looping through
the items collection. Is this possible? (Something like 'item.delete'.. .)

Thanks.

--
mo*******@nospa m.com
Nov 18 '05 #1
4 4572
moondaddy -
What I would recommend is that you use the events built into the grid control to handle the functions that you perform. I use the OnEditCommand OnDeleteCommand and the OnUpdateCommand in either a datalist or grid to handle the functions that you explain below. Below is an example of the OnDeleteCommand that would solve your checkbox problem below (this is from a datalist - but works with datagrid, too):

Sub listImages_Dele teCommand(ByVal s As Object, ByVal e As DataListCommand EventArgs)
Dim iImageID As String = listImages.Data Keys(e.Item.Ite mIndex)
Dim ImageName As String
Dim BaseImageFileLo c = ConfigurationSe ttings.AppSetti ngs("BaseFileLo c") & "images\"
Dim findDivisionNam e As New globalFunctions
Dim sDivisionName As String
With findDivisionNam e
.GalleryID = ddlGalleryID.Se lectedItem.Valu e
sDivisionName = .findDivisionNa me
End With

sSQL = "select imagename from images where imageid = " & iImageID
oConn.Open()
Dim cmd1 As New SqlCommand(sSQL , oConn)
Dim dr As SqlDataReader = cmd1.ExecuteRea der

Do While dr.Read
ImageName = dr.Item("imagen ame")
Loop
dr.Close()
oConn.Close()

'Response.Write (BaseImageFileL oc & sDivisionName & "\" & ImageName)

File.Delete(Bas eImageFileLoc & sDivisionName & "\" & ImageName)

Dim deleteImage As New imagesDB
With deleteImage
.oConn = oConn
.ImageID = iImageID
.deleteImage()
End With
listImages.Edit ItemIndex = -1
BindDataList()
End Sub

There are a lot of extra pieces of this Sub - but the important parts are the e.Items collection - that is the acutal row in the grid that you are working on. Let me know if this helps.

"moondaddy" wrote:
I have a datagrid where a user can edit a number in one of the columns for a
quantity value. On the postback I loop through all of the datagrid items
and if the quantity has changed, then I update the value of the extended
price cell for that datagrid item.

Also, the datagrid has a checkbox in each row called "Remove" where if the
checkbox is checked I delete that row from the underlying datasource and set
a flag which tells me to rebind the datagrid before the page sent back to
the client. Rather that raising a flag and rebinding the datagrid, I was
hoping I could simply remove that datagrid item (row) as I'm looping through
the items collection. Is this possible? (Something like 'item.delete'.. .)

Thanks.

--
mo*******@nospa m.com

Nov 18 '05 #2
Hi Moondaddy,

In addition to rlthurston's suggestion on use the DataGrid's buildin
DeleteCommand event, here are some of my suggestions:

Since the Webform DataGrid control (as well as DataList or Repeater) is
Template databinding control, it's items(displayed records) are all
generated from the binded datasource and then stored in viewstate. We can
set some certain rows(in the DataGrid's Items collection)'s Visible to
false to hide them but can't remove them this way. And if we want to
represent the changes in the DataSource, the formal and recommended
approach is just rebind the grid with updated datasource. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

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

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3
Hi Moondaddy,

In addition to rlthurston's suggestion on use the DataGrid's buildin
DeleteCommand event, here are some of my suggestions:

Since the Webform DataGrid control (as well as DataList or Repeater) is
Template databinding control, it's items(displayed records) are all
generated from the binded datasource and then stored in viewstate. We can
set some certain rows(in the DataGrid's Items collection)'s Visible to
false to hide them but can't remove them this way. And if we want to
represent the changes in the DataSource, the formal and recommended
approach is just rebind the grid with updated datasource. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

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

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4
Thanks for the above 2 postings. Since I can't actually remove or delete
the row, I'll simply rebind the grid. On each postback I loop through the
grid to capture any changes and then update the database. If I leave the
rows there and make them not visible, then I'll just have to do extra
processing and logic to account for that.

Thanks again.

--
mo*******@nospa m.com
"Steven Cheng[MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:o$******** ********@cpmsft ngxa10.phx.gbl. ..
Hi Moondaddy,

In addition to rlthurston's suggestion on use the DataGrid's buildin
DeleteCommand event, here are some of my suggestions:

Since the Webform DataGrid control (as well as DataList or Repeater) is
Template databinding control, it's items(displayed records) are all
generated from the binded datasource and then stored in viewstate. We can
set some certain rows(in the DataGrid's Items collection)'s Visible to
false to hide them but can't remove them this way. And if we want to
represent the changes in the DataSource, the formal and recommended
approach is just rebind the grid with updated datasource. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

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

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #5

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

Similar topics

0
1031
by: Martijn de Jong | last post by:
Hello, For a while i'm trying to creat an datagrid composite control which has dynamicly build columns en internationalized headers. Al this works at this moment only some problems occurs when creating an events on the datagrid when the itemcreated event is fired. I post the code for this event below. private void _datagrid_ItemCreated(object sender, DataGridItemEventArgs e){ if ((e.Item.ItemType == ListItemType.Item) ||...
0
915
by: Martijn de Jong | last post by:
Hello, For a while i'm trying to creat an datagrid composite control which has dynamicly build columns en internationalized headers. Al this works at this moment only some problems occurs when creating an events on the datagrid when the itemcreated event is fired. I post the code for this event below. private void _datagrid_ItemCreated(object sender, DataGridItemEventArgs e){ if ((e.Item.ItemType == ListItemType.Item) ||...
0
3091
by: Michal Raatz | last post by:
Welcome. I have a common problem with the datagrid: when the data source contains html tags (<script>document.location.href='www.badsite.com'</script> for example) the page with the datagrid becomes unsafe. I have found two possible solutions in the net: - using template columns and HTMLEncode - using ItemCreated event of the datagrid Both method works but the grid grows drasticly. And when I have dynamicly created SQL query, used with...
7
1372
by: ruca | last post by:
Hi, How can I fill a datagrid without accessing to a database or any type of file, only filling with a command button like this: I have 3 textboxes that I must fill, and a button that when clicked pass text of this 3 textboxes to my datagrid. I want to manage (edit , update, etc) a datagrid but without accessing DataBase. The unique interaction with that DB is a button that save all that I have in datagrid into DB.
3
1146
by: Bad_Kid | last post by:
How can I dynamicly create a datagrid? (first I read a datatable from a database, see how many atributes does it have (n) and then build a datagrid with n columns...)??? (c#, asp.net)
5
3395
by: js | last post by:
I am having a problem with a dynamicly added DataGrid that always shows the first data page even the message in the DataGrid.PreRender shows the correct datapage as the DropDownList control's SelectedIndex. The DataGrid CurrentPageIndex is controlled by a DropDownList control. Anyone knows what might be going wrong? Thanks. The addDataGrid() is fired by the following 3 events: private void btnLookup_Click(object sender,...
2
962
by: ElanKathir .S.N | last post by:
Hi ! How to populate the Datagrid with out using the Dataset? I want to add the record dynamicly. Thanks & Regards Elankathir, B'lore, India.
5
2034
by: jason | last post by:
Hi, all How can I update data (multiple rows, but not every rows) using dataset in datagrid? I mean is there any way I can let datagrid know which row(s)/column(s) has been modified and update them at database? Thanks.
9
3378
by: John Hernry | last post by:
I have been watching the dotnet newsgroups for a couple of weeks now and scouring the net looking for a solution to my datagrid find functionality. With no luck. I am hoping that you can help me. I am an old VB6 coder used to using Sheridan controls, and I am just starting to learn the .net world. I am upgrading my music catalogue database, where the data is stored in an Access mdb file.
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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
10410
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
10200
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
10139
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
9020
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...
0
6769
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2909
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.