473,466 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Values inside a DataGrid

Another DGrid question...

I can not access the values of a cell in a datagrid unless
I make them visible. I do not want these fields
displayed. I only want to use the values to run a stored
procedure off of. I access them right now using the
item.cell().control method.
Here's the code:

Dim intTrxid As Integer
Dim rda As RadioButtonList
Dim vrda As String
Dim txtrem As TextBox
Dim remarks As String
Dim icn As Integer
Dim newicn As Integer
Dim datcurrent As Date
Dim FY As String
Dim newyear As Date
Dim strnewicn As String

Dim txtimptype As TextBox
Dim imptype As String
Dim txtuns As TextBox
Dim uns As String
Dim GPCcontrolno As String
Dim imp As String
'get value of unitid to find icn#
Dim txtunit As TextBox
Dim strUnit As String
Dim intunit As Integer
txtunit = e.Item.Cells(8).Controls(0)
strunit = txtunit.Text
lblUnitid.Text = strUnit
intunit = CType(strUnit, Integer)
'intUnit = 1
SqlSelectCommand5.Parameters("@unitid").Value =
intUnit
SqlDataAdapter5.Fill(DsICN1)
lblControlNo.DataBind()

datcurrent = Date.Now.ToString("d")
newyear = DateAdd(DateInterval.Year, 1, datcurrent)
FY = DatePart(DateInterval.Year, newyear)

icn = CType(lblControlNo.Text, Integer)
newicn = icn + 1
strnewicn = CStr(newicn)
lblnewicn.Text = newicn
intTrxid = dgApproval.DataKeys(e.Item.ItemIndex)
rda = e.Item.FindControl("rdApproval")
vrda = rda.SelectedItem.Value
txtrem = e.Item.FindControl("txtccmremarks")
remarks = txtrem.Text

txtimptype = e.Item.Cells(9).Controls(0)
imptype = txtimptype.Text
txtuns = e.Item.Cells(10).Controls(0)
uns = txtuns.Text
imp = Left(txtimptype.Text, 1)

GPCcontrolno = uns & FY & imp & strnewicn
If vrda = "A" Then
SqlUpdateCommand2.Parameters("@icn").Value =
GPCcontrolno
SqlUpdateCommand2.Parameters("@ta").Value = 1
SqlUpdateCommand2.Parameters("@td").Value = 0
Else
If vrda = "D" Then
SqlUpdateCommand2.Parameters("@icn").Value
= "0"
SqlUpdateCommand2.Parameters("@ta").Value
= 0
SqlUpdateCommand2.Parameters("@td").Value
= 1
End If
End If
SqlUpdateCommand2.Parameters("@remarks").Value =
remarks
SqlUpdateCommand2.Parameters("@tid").Value =
intTrxid
SqlConnection1.Open()
SqlUpdateCommand2.ExecuteNonQuery()

dgApproval.EditItemIndex = -1
BindApproval()
dgdetails.Visible = False

SqlInsertCommand1.Parameters("@unitid").Value =
intunit
SqlInsertCommand1.Parameters("@FY").Value = FY
SqlInsertCommand1.Parameters("@newicn").Value =
newicn
SqlInsertCommand1.ExecuteNonQuery()
SqlConnection1.Close()
End Sub

Thanks in advance...

Derek M

Jul 21 '05 #1
1 4266
Hello Derek,

Thanks for your post. As I understand, you are using DataGrid in a ASP .NET
Web form. The problem you are facing is that you cannot access the value of
a cell when it is invisible in datagrid. Please correct me is there is any
misunderstanding. Now I'd like to share the following information with you:

In which event are you trying to access the item.cell().control?
If it is in the edit event and you have set the corresponding column as
visible=false, you may not get any values because there is no corresponding
textbox shown in the browser since the column is hidden. When a column is
hidden, it's values are not written to the table that displays the DataGrid
in the browser. That is why if you try to access a corresponding control
from the posted data, you will not get anything back. Based on my
experience, there are two methods to work around this problem:

Method 1
========
As you know, the values for the hidden column are stored in the viewstate
and they will be available during the postback. To work around this
problem, you can access them by the following method:

DataGrid.Items().Cells().Text

Method 2
========
You can persist the dataset that was bound to the dataGrid and access the
values for your hidden column from it.

Please feel free to let me know if you have any probles or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #2

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

Similar topics

0
by: Maziar Aflatoun | last post by:
Hi everyone, I have a datagrid that I create inside a Repeater at runtime. I have defined a checkbox beside each row so that users can select multiple rows. <asp:datagrid id="dgProducts"...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
7
by: Scott Schluer | last post by:
Hi All, I have a functioning datagrid on "Page 1" that displays order information for a single order (this is for an e-commerce site). It's actually a combination of a couple datagrids to...
3
by: Moojjoo | last post by:
I created an user control (.ascx file) with a DropDownList (DDL) with the following code behide: public string Selected_dept_value() { string dept_value = dept_dropdown.SelectedValue; return...
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
1
by: Derek | last post by:
Another DGrid question... I can not access the values of a cell in a datagrid unless I make them visible. I do not want these fields displayed. I only want to use the values to run a stored...
8
by: Alan Silver | last post by:
Hello, I have a repeater that has code like this... <ItemTemplate> <asp:CheckBox ID="chkDelete" Text="" RunAt="server"/> .... other stuff goes here </ItemTemplate> There is a button below...
5
by: venkateshcnpl | last post by:
Hi,I am New To This . I have to check the duplications of values entered in textbox which is placed inside the datagrid.And the Number of textbox is not constant it is dynamically added can any one...
1
by: Joe Blauth | last post by:
Hi all, I was running into a problem with a gridview under ASP.net. What I am trying to do is binding the DataSource dynamically in a way that enables me to edit the rows in the Gridview. This...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.