473,626 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding an item to the datagrid

I have a datagrid (with viewstate enabled), and my edit/update/delete
buttons in the grid are all working fine. I have a textbox and a button
underneath the grid for adding items to the grid. When the button is
clicked, the following code runs:

Dim drNew As DataRow = dsTrades.Tables ("Trades").NewR ow ' create
new row
dsTrades.Tables ("Trades").Rows .Add(drNew)
' add new row to table
drNew("TradeNam e") = Request.Form("t xtNewTrade") '
get TradeName from post
daTrades.Update (dsTrades)
' update database
daTrades.Fill(d sTrades)
' re-load the sorted list...
dgTrades.DataBi nd()
' bind the grid

The item adds properly to the database, but the newly added item always
appears as the first row in the grid, if the grid is currently on the first
page, regardless of where it should appear (it is a sorted list). Calling
the grid page again fixes the problem (i.e. the item begins to show up in
the correct place). My basic question is: why doesn't the Fill() and
DataBind() when I am adding refresh the grid before rendering?

Thanks,

Chris
Nov 18 '05 #1
3 1475
"Chris Leuty" <chris.leuty-at-nospam.brinker. com> wrote in message
news:u7******** ******@TK2MSFTN GP09.phx.gbl...
I have a datagrid (with viewstate enabled), and my edit/update/delete
buttons in the grid are all working fine. I have a textbox and a button
underneath the grid for adding items to the grid. When the button is
clicked, the following code runs:

Dim drNew As DataRow = dsTrades.Tables ("Trades").NewR ow ' create new row
dsTrades.Tables ("Trades").Rows .Add(drNew)
' add new row to table
drNew("TradeNam e") = Request.Form("t xtNewTrade") ' get TradeName from post
daTrades.Update (dsTrades)
' update database
daTrades.Fill(d sTrades)
' re-load the sorted list...
dgTrades.DataBi nd()


Why would this be sorted?
--
John Saunders
johnwsaundersii i at hotmail
Nov 18 '05 #2
Technical Why: The proc returning the data is sorting the data
alphabetically. (It is a list of trade skills).
Business Why: That is how they want to see the data.
"John Saunders" <jo************ **@notcoldmail. com> wrote in message
news:Oj******** ********@TK2MSF TNGP09.phx.gbl. ..
"Chris Leuty" <chris.leuty-at-nospam.brinker. com> wrote in message
news:u7******** ******@TK2MSFTN GP09.phx.gbl...
I have a datagrid (with viewstate enabled), and my edit/update/delete
buttons in the grid are all working fine. I have a textbox and a button
underneath the grid for adding items to the grid. When the button is
clicked, the following code runs:

Dim drNew As DataRow = dsTrades.Tables ("Trades").NewR ow '

create
new row
dsTrades.Tables ("Trades").Rows .Add(drNew)
' add new row to table
drNew("TradeNam e") = Request.Form("t xtNewTrade")

'
get TradeName from post
daTrades.Update (dsTrades)
' update database
daTrades.Fill(d sTrades)
' re-load the sorted list...
dgTrades.DataBi nd()


Why would this be sorted?
--
John Saunders
johnwsaundersii i at hotmail

Nov 18 '05 #3
I cleared the dataset before filling it, and the grid refreshed in the
correct order.

All fixed.

"Chris Leuty" <chris.leuty-at-nospam.brinker. com> wrote in message
news:eV******** *****@TK2MSFTNG P12.phx.gbl...
Technical Why: The proc returning the data is sorting the data
alphabetically. (It is a list of trade skills).
Business Why: That is how they want to see the data.
"John Saunders" <jo************ **@notcoldmail. com> wrote in message
news:Oj******** ********@TK2MSF TNGP09.phx.gbl. ..
"Chris Leuty" <chris.leuty-at-nospam.brinker. com> wrote in message
news:u7******** ******@TK2MSFTN GP09.phx.gbl...
I have a datagrid (with viewstate enabled), and my edit/update/delete
buttons in the grid are all working fine. I have a textbox and a button underneath the grid for adding items to the grid. When the button is
clicked, the following code runs:

Dim drNew As DataRow = dsTrades.Tables ("Trades").NewR ow '

create
new row
dsTrades.Tables ("Trades").Rows .Add(drNew)
' add new row to table
drNew("TradeNam e") = Request.Form("t xtNewTrade")

'
get TradeName from post
daTrades.Update (dsTrades)
' update database
daTrades.Fill(d sTrades)
' re-load the sorted list...
dgTrades.DataBi nd()


Why would this be sorted?
--
John Saunders
johnwsaundersii i at hotmail


Nov 18 '05 #4

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

Similar topics

5
5276
by: Sue | last post by:
On code-behind page: (attributes set programatically for each of these elements) linkbutton added to tablecell textbox added to tablecell tablecells added to tablerow tablerow added to table (table.ID is TestTable) On .aspx page: <HeaderTemplate> <asp:Table ID="TestTable" runat="Server" /> </HeaderTemplate>
0
2998
by: Andrés Giraldo | last post by:
Hi! I'm adding an asp button to a datagrid on the ItemDataBound event, when the user clicks on this button, I basically remove the button and create other 2 buttons... my problem is.. the 2 last buttons doesn't fire his events... what I'm doing wrong? Thanks!
2
3626
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete a row. Everything works just fine. BUT I would like to add a button to (for example) the DataGrid header, which when pressed will add a new row to the datagrid. This should then allow the user to enter information into text boxes (in some...
3
4869
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
8
4434
by: sumit | last post by:
Hi, I want to add one java script function on the click of page button of datagrid. But how to get UI control of page button so that i should be able to add attribute for onClick event. Please suggest Sumit
2
2427
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via the Columns dialog box from the properties of the datagrid, on the left that contains a select button. So now, when you press the button the whole row is highlighted. Now, what I want to do is have the user highlight as many rows as they wish...
2
4229
by: saleek | last post by:
I was wondering if there is a way I can add an extra header to a datagrid? I found this solution on the internet - but it seems quite old and didn't work for me. http://www.dotnet247.com/247reference/msgs/13/69744.aspx It recommends the following: Private Sub DataGrid1_PreRender(ByVal sender As Object, ByVal e As
2
1914
by: Tomek R. | last post by:
Hello ! I've got weird problem when adding new datagrid item. Here is the situation: my grid dgDeps is binded to DepartmentList arraylist, stored in Session between round-trips.. To add new item I press buttton with ibNewDep_Click event. After that the grid is in edit state and I can modify new item, it has some text, set as default - "<nowy wydzia³>". But - this is the weirdness - when I add some text following the default value
5
4654
by: Aaron Ackerman | last post by:
I have a bound combobox the appears on a cell within the column of my bound grid when the user clicks on a cell n(In my vb.net WinForm app). I am trying to allow the adding of an item to that bound combo by allowing the user to dynamically type in the new value directly in the combo box whcih in turn updates the lookup table and then when they have finished leaves that particular cell on the grid with the correct value. Seems...
15
3095
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an OnSelectedIndex event is not fired if you select the first item. Does anyone know of an easy way to do this?
0
8192
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
8696
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
8502
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...
1
6119
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
5571
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
4090
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...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1504
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.