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

Home Posts Topics Members FAQ

change value of textbox in datagrid

hello,
new to vb.net, have a few questions about DataGrid. I have a dataGrid
that is working pulling a dataset back from a stored proc and binding
to the datagrid for display
the datagrid's first column is a textbox(Templat eColumn), the other 3
columns are just display(BoundCo lumn).

(1) if the value of the textbox is 0, then i'd like to change it null,
so the box is empty

i tried this...

For Each PickGridItem In draftPickGrid.I tems
If Convert.ToInt16 (CType(PickGrid Item.FindContro l("tPriority" ),
TextBox).Text) = 0 Then
CType(PickGridI tem.FindControl ("tPriority" ), TextBox).Text = ""
End If
Next

this or variation of it didn't work. help?
(2) after the user click the button, I have a function that kicks off
that i wanted to loop the dataset, get a few values (one if which is
the textbox), and then call a proc to update the data

i tried this....

For Each DemoGridItem In draftPickGrid.I tems

EventId = Convert.ToInt16 (DemoGridItem.C ells(2).Text)
Priority =
Convert.ToInt16 (CType(DemoGrid Item.FindContro l("tPriority" ),
TextBox).Text)
DraftPicks.Upda teDraftPick(gro upID, EventId, userID, Priority)
Next

I was getting a "Object reference not set to an instance of an object"
on Priority

also tried these lines to capture the value of the textbox

Dim tb As TextBox
tb = DemoGridItem.Fi ndControl("tPri ority")
Priority = Convert.ToInt16 (tb.Text)

that didn't work either, same error

i'm using visual studio 2003 and put a break point on the function
that is called to loop and call the update proc, i have these
declaration lines at the top of the function

Dim EventId As Integer
Dim Priority As Integer
Dim DemoGridItem As DataGridItem
Dim DraftPicks As New DraftPicksDB
it will skip over the first three Dim lines, Dim the 4th and then move
to the for loop. in the loop when i hit the priority (textbox)
processing line the error is then thrown.

any help/advice would be appreciated - sample code is always welcome
:)
thanks in advance!

Jan 30 '06 #1
2 12582
I would think it is better to ask the data container for zero length strings
and set the value to null from there.

my perferred way (barring stored procedures.)

for each dr as datarow in ctype(dbgdata.d atasource, datatable)
if not dr.isnull("Fiel dToCheck") andalso ctype(dr("Field ToCheck"),
string).length= 0 then
dr.beginedit
dr("FieldToChec k") = system.dbnull.v alue
dr.endedit
end if
next

you can become even more specific by using

for each dr as datarow in ctype(dbgdata.d atasource,
datatable).getc hanges(Added or Modified)

Another thing you can try is to monitor when the selected row of a datagrid
changes.

private m_CurrentRowInd ex as integer
privatee m_CurrencyManag er as CurrencyManager

private sub form_load
m_CurrencyManag er =
ctype(me.bindin gcontext(dbgdat a.datasource),c urrencymanager)

'Optionally issue
m_CurrencyManag er.Refresh
end sub

private sub m_CurrencyManag er_PositionChan ged(Sender, e) handles
m_CurrencyManag er.PositionChan ged
'Todo: add logic if you allow column sorting....

if me.dbgDatga.Cur rentrowIndex <> m_currentrowind ex then

dim dr as datarow= ctype(dbgdata.d atasource,
datatable).rows (m_currentrowin dex)

if not dr.isnull("Fiel dToCheck") andalso ctype(dr("Field ToCheck"),
string).length= 0 then
dr.beginedit
dr("FieldToChec k") = system.dbnull.v alue
dr.endedit
end if

dbgDatga.Curren trowIndex = m_currentrowind ex

'Optionally issue
m_CurrencyManag er.Refresh

end if

end sub

"simon" <me@here.com> wrote in message
news:hk******** *************** *********@4ax.c om...
hello,
new to vb.net, have a few questions about DataGrid. I have a dataGrid
that is working pulling a dataset back from a stored proc and binding
to the datagrid for display
the datagrid's first column is a textbox(Templat eColumn), the other 3
columns are just display(BoundCo lumn).

(1) if the value of the textbox is 0, then i'd like to change it null,
so the box is empty

i tried this...

For Each PickGridItem In draftPickGrid.I tems
If Convert.ToInt16 (CType(PickGrid Item.FindContro l("tPriority" ),
TextBox).Text) = 0 Then
CType(PickGridI tem.FindControl ("tPriority" ), TextBox).Text = ""
End If
Next

this or variation of it didn't work. help?
(2) after the user click the button, I have a function that kicks off
that i wanted to loop the dataset, get a few values (one if which is
the textbox), and then call a proc to update the data

i tried this....

For Each DemoGridItem In draftPickGrid.I tems

EventId = Convert.ToInt16 (DemoGridItem.C ells(2).Text)
Priority =
Convert.ToInt16 (CType(DemoGrid Item.FindContro l("tPriority" ),
TextBox).Text)
DraftPicks.Upda teDraftPick(gro upID, EventId, userID, Priority)
Next

I was getting a "Object reference not set to an instance of an object"
on Priority

also tried these lines to capture the value of the textbox

Dim tb As TextBox
tb = DemoGridItem.Fi ndControl("tPri ority")
Priority = Convert.ToInt16 (tb.Text)

that didn't work either, same error

i'm using visual studio 2003 and put a break point on the function
that is called to loop and call the update proc, i have these
declaration lines at the top of the function

Dim EventId As Integer
Dim Priority As Integer
Dim DemoGridItem As DataGridItem
Dim DraftPicks As New DraftPicksDB
it will skip over the first three Dim lines, Dim the 4th and then move
to the for loop. in the loop when i hit the priority (textbox)
processing line the error is then thrown.

any help/advice would be appreciated - sample code is always welcome
:)
thanks in advance!

Jan 30 '06 #2
thank you for the reply.
i have figured out what i was looking to do (may not be the best way
so please feel free to comment)

for setting the value of a textbox to null if it contain a "0" after
loading/binding it (for display purposes not storage in the db),
i did....

Private Sub SetPriorityZero ToNull()

Dim DemoGridItem As DataGridItem

For Each DemoGridItem In draftPickGrid.I tems
If CType(DemoGridI tem.FindControl ("tPriority" ),
TextBox).Text = "0" Then
CType(DemoGridI tem.FindControl ("tPriority" ),
TextBox).Text = ""
End If
Next

End Sub
the other problems i was having was due to a typo in my code when
naming the ID of the textbox in the grid. good grief :)

On Mon, 30 Jan 2006 09:40:36 -0600, "AMDRIT" <am****@hotmail .com>
wrote:
I would think it is better to ask the data container for zero length strings
and set the value to null from there.

my perferred way (barring stored procedures.)

for each dr as datarow in ctype(dbgdata.d atasource, datatable)
if not dr.isnull("Fiel dToCheck") andalso ctype(dr("Field ToCheck"),
string).length =0 then
dr.beginedit
dr("FieldToChec k") = system.dbnull.v alue
dr.endedit
end if
next

you can become even more specific by using

for each dr as datarow in ctype(dbgdata.d atasource,
datatable).get changes(Added or Modified)

Another thing you can try is to monitor when the selected row of a datagrid
changes.

private m_CurrentRowInd ex as integer
privatee m_CurrencyManag er as CurrencyManager

private sub form_load
m_CurrencyManag er =
ctype(me.bindi ngcontext(dbgda ta.datasource), currencymanager )

'Optionally issue
m_CurrencyManag er.Refresh
end sub

private sub m_CurrencyManag er_PositionChan ged(Sender, e) handles
m_CurrencyMana ger.PositionCha nged
'Todo: add logic if you allow column sorting....

if me.dbgDatga.Cur rentrowIndex <> m_currentrowind ex then

dim dr as datarow= ctype(dbgdata.d atasource,
datatable).row s(m_currentrowi ndex)

if not dr.isnull("Fiel dToCheck") andalso ctype(dr("Field ToCheck"),
string).length =0 then
dr.beginedit
dr("FieldToChec k") = system.dbnull.v alue
dr.endedit
end if

dbgDatga.Curren trowIndex = m_currentrowind ex

'Optionally issue
m_CurrencyManag er.Refresh

end if

end sub

"simon" <me@here.com> wrote in message
news:hk******* *************** **********@4ax. com...
hello,
new to vb.net, have a few questions about DataGrid. I have a dataGrid
that is working pulling a dataset back from a stored proc and binding
to the datagrid for display
the datagrid's first column is a textbox(Templat eColumn), the other 3
columns are just display(BoundCo lumn).

(1) if the value of the textbox is 0, then i'd like to change it null,
so the box is empty

i tried this...

For Each PickGridItem In draftPickGrid.I tems
If Convert.ToInt16 (CType(PickGrid Item.FindContro l("tPriority" ),
TextBox).Text) = 0 Then
CType(PickGridI tem.FindControl ("tPriority" ), TextBox).Text = ""
End If
Next

this or variation of it didn't work. help?
(2) after the user click the button, I have a function that kicks off
that i wanted to loop the dataset, get a few values (one if which is
the textbox), and then call a proc to update the data

i tried this....

For Each DemoGridItem In draftPickGrid.I tems

EventId = Convert.ToInt16 (DemoGridItem.C ells(2).Text)
Priority =
Convert.ToInt16 (CType(DemoGrid Item.FindContro l("tPriority" ),
TextBox).Text)
DraftPicks.Upda teDraftPick(gro upID, EventId, userID, Priority)
Next

I was getting a "Object reference not set to an instance of an object"
on Priority

also tried these lines to capture the value of the textbox

Dim tb As TextBox
tb = DemoGridItem.Fi ndControl("tPri ority")
Priority = Convert.ToInt16 (tb.Text)

that didn't work either, same error

i'm using visual studio 2003 and put a break point on the function
that is called to loop and call the update proc, i have these
declaration lines at the top of the function

Dim EventId As Integer
Dim Priority As Integer
Dim DemoGridItem As DataGridItem
Dim DraftPicks As New DraftPicksDB
it will skip over the first three Dim lines, Dim the 4th and then move
to the for loop. in the loop when i hit the priority (textbox)
processing line the error is then thrown.

any help/advice would be appreciated - sample code is always welcome
:)
thanks in advance!


Jan 31 '06 #3

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

Similar topics

3
9458
by: Ronald S. Cook | last post by:
Hi all, I have an ASP.NET DataGrid wherein there is an edit link for each row. Upon clicking the link, certan fields in that row display in text boxes so that they may be edited. I would like some textboxes to be wider, some narrower. By default, they are all the same pre-defined width. Does anyone know how I can do this? Thanks very much,
6
3317
by: Alpha | last post by:
I have several textboxes that I need to chang the text when the selection row is changed in a datagrid. I have the following code. This textbox displayes the initial selection but when I click on different rows in the datagrid, the textbox content doesn't change to reflect the change. How can I address this? Also, If the user change the text in the textbox then how do I refesh the display in the datagrid to reflect the changes? ...
2
3368
by: Tor Inge Rislaa | last post by:
How to change row height in a DataGrid I have DataGrid that is filled with data from a table in a DataSet. The content of the cells is text of more than one line (as a note field). What I want is to set the height of the row based on the number of lines in it. The row height of each row in the table may be different from each other. Is there a way to do this?
1
1622
by: Michael via .NET 247 | last post by:
I have a datagrid with the columns defined in the aspx <columns> <asp:TemplateColumn HeaderText="Hours" ItemStyle-Width="1%"ItemStyle-HorizontalAlign="Center"> <ItemTemplate> <asp:TextBox Columns="2" EnableViewState="False" ID="Hours"Runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateColumn> ... </columns>
6
11276
by: timbobd | last post by:
I have a Windows form that displays a database table in a DataGrid. When you click on a row, the row's values get copied to bound TextBoxes below, and when the "Save" button is clicked the database is updated (as is the DataGrid row) with changed values in the TextBoxes. Here are some observations: 1) When changes are typed into a text box and "Save" is clicked, the changes are reflected in the DataSet.Tables().Rows().ItemArray value, but...
2
2122
by: Billy | last post by:
Change DataGrid EditControl On Data Value Hi, I have a datagrid, and on editing, I want to change the control in the third colunm based on the value of the first column. The value in the first column can only be either "Text" or "Image", which is selcted in a dropdown list.
0
1815
by: zhuang | last post by:
Hi, Adding combobox to datagrid has been posted many times. I have a datagrid which has multiple combobox columns and normal textbox columns. But how could I change other combo box values at the same row when user change the value of one of the combo box. The textbox value in the same row could be changed by modifying the
0
1190
by: joinzulfi | last post by:
Dear fellows! I have designed a form having SaleMasterTable and SaleDetailTable. SaleDetailTable is Bounded with DataGrid. Now I want that if in2nd Column's cell (it is combobox) value is changed then as a result of this change in 3rd column's cell (it is textbox) value is inserted from another table in database named Product.
1
1482
by: AliRezaGoogle | last post by:
Dear members, I have a datagrid and a textbox on my form. I bound both of them to a common datasource( an arbitrary datatable). When I change a text inside textbox I expect that value of same column in datagride also change and be equal to new value entered inside textbox. But this change reflects to datagrid just when I change selected row in the datagrid.
0
8268
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
8202
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
8707
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
8641
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...
0
8510
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
7199
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
6125
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
4093
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
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.