473,378 Members | 1,370 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,378 software developers and data experts.

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*******@nospam.com
Nov 18 '05 #1
4 4551
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_DeleteCommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
Dim iImageID As String = listImages.DataKeys(e.Item.ItemIndex)
Dim ImageName As String
Dim BaseImageFileLoc = ConfigurationSettings.AppSettings("BaseFileLoc") & "images\"
Dim findDivisionName As New globalFunctions
Dim sDivisionName As String
With findDivisionName
.GalleryID = ddlGalleryID.SelectedItem.Value
sDivisionName = .findDivisionName
End With

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

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

'Response.Write(BaseImageFileLoc & sDivisionName & "\" & ImageName)

File.Delete(BaseImageFileLoc & sDivisionName & "\" & ImageName)

Dim deleteImage As New imagesDB
With deleteImage
.oConn = oConn
.ImageID = iImageID
.deleteImage()
End With
listImages.EditItemIndex = -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*******@nospam.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*******@nospam.com
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:o$****************@cpmsftngxa10.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
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...
0
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...
0
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...
7
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...
3
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
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...
2
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
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...
9
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....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.