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

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(TemplateColumn), the other 3
columns are just display(BoundColumn).

(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.Items
If Convert.ToInt16(CType(PickGridItem.FindControl("tP riority"),
TextBox).Text) = 0 Then
CType(PickGridItem.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.Items

EventId = Convert.ToInt16(DemoGridItem.Cells(2).Text)
Priority =
Convert.ToInt16(CType(DemoGridItem.FindControl("tP riority"),
TextBox).Text)
DraftPicks.UpdateDraftPick(groupID, 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.FindControl("tPriority")
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 12557
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.datasource, datatable)
if not dr.isnull("FieldToCheck") andalso ctype(dr("FieldToCheck"),
string).length=0 then
dr.beginedit
dr("FieldToCheck") = system.dbnull.value
dr.endedit
end if
next

you can become even more specific by using

for each dr as datarow in ctype(dbgdata.datasource,
datatable).getchanges(Added or Modified)

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

private m_CurrentRowIndex as integer
privatee m_CurrencyManager as CurrencyManager

private sub form_load
m_CurrencyManager =
ctype(me.bindingcontext(dbgdata.datasource),curren cymanager)

'Optionally issue
m_CurrencyManager.Refresh
end sub

private sub m_CurrencyManager_PositionChanged(Sender, e) handles
m_CurrencyManager.PositionChanged
'Todo: add logic if you allow column sorting....

if me.dbgDatga.CurrentrowIndex <> m_currentrowindex then

dim dr as datarow= ctype(dbgdata.datasource,
datatable).rows(m_currentrowindex)

if not dr.isnull("FieldToCheck") andalso ctype(dr("FieldToCheck"),
string).length=0 then
dr.beginedit
dr("FieldToCheck") = system.dbnull.value
dr.endedit
end if

dbgDatga.CurrentrowIndex = m_currentrowindex

'Optionally issue
m_CurrencyManager.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(TemplateColumn), the other 3
columns are just display(BoundColumn).

(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.Items
If Convert.ToInt16(CType(PickGridItem.FindControl("tP riority"),
TextBox).Text) = 0 Then
CType(PickGridItem.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.Items

EventId = Convert.ToInt16(DemoGridItem.Cells(2).Text)
Priority =
Convert.ToInt16(CType(DemoGridItem.FindControl("tP riority"),
TextBox).Text)
DraftPicks.UpdateDraftPick(groupID, 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.FindControl("tPriority")
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 SetPriorityZeroToNull()

Dim DemoGridItem As DataGridItem

For Each DemoGridItem In draftPickGrid.Items
If CType(DemoGridItem.FindControl("tPriority"),
TextBox).Text = "0" Then
CType(DemoGridItem.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.datasource, datatable)
if not dr.isnull("FieldToCheck") andalso ctype(dr("FieldToCheck"),
string).length=0 then
dr.beginedit
dr("FieldToCheck") = system.dbnull.value
dr.endedit
end if
next

you can become even more specific by using

for each dr as datarow in ctype(dbgdata.datasource,
datatable).getchanges(Added or Modified)

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

private m_CurrentRowIndex as integer
privatee m_CurrencyManager as CurrencyManager

private sub form_load
m_CurrencyManager =
ctype(me.bindingcontext(dbgdata.datasource),curre ncymanager)

'Optionally issue
m_CurrencyManager.Refresh
end sub

private sub m_CurrencyManager_PositionChanged(Sender, e) handles
m_CurrencyManager.PositionChanged
'Todo: add logic if you allow column sorting....

if me.dbgDatga.CurrentrowIndex <> m_currentrowindex then

dim dr as datarow= ctype(dbgdata.datasource,
datatable).rows(m_currentrowindex)

if not dr.isnull("FieldToCheck") andalso ctype(dr("FieldToCheck"),
string).length=0 then
dr.beginedit
dr("FieldToCheck") = system.dbnull.value
dr.endedit
end if

dbgDatga.CurrentrowIndex = m_currentrowindex

'Optionally issue
m_CurrencyManager.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(TemplateColumn), the other 3
columns are just display(BoundColumn).

(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.Items
If Convert.ToInt16(CType(PickGridItem.FindControl("tP riority"),
TextBox).Text) = 0 Then
CType(PickGridItem.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.Items

EventId = Convert.ToInt16(DemoGridItem.Cells(2).Text)
Priority =
Convert.ToInt16(CType(DemoGridItem.FindControl("tP riority"),
TextBox).Text)
DraftPicks.UpdateDraftPick(groupID, 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.FindControl("tPriority")
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
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...
6
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...
2
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...
1
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...
6
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...
2
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...
0
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...
0
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...
1
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...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...

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.