473,385 Members | 2,005 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,385 software developers and data experts.

GridView - Retrieve invisible column information

Mel
I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:

gvParts.Rows(e.RowIndex).Cells(8).Text
Any help would be greatly appreciated.

Jul 25 '07 #1
9 4765
If they're always going to be invisible, as such, you can't access them
during run-time.
to get around that, you can copy the labels or textboxes from the invisible
columns into visible columns, making the labels/textboxes invisible - then,
you can programmatically use the FindControl method in that particular row,
to find you data to validate against.

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com

"Mel" <ML********@gmail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
>I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:

gvParts.Rows(e.RowIndex).Cells(8).Text
Any help would be greatly appreciated.

Jul 25 '07 #2
Mel
On Jul 25, 2:15 pm, "David Wier" <davidw...@davidwier.nospam.com>
wrote:
If they're always going to be invisible, as such, you can't access them
during run-time.
to get around that, you can copy the labels or textboxes from the invisible
columns into visible columns, making the labels/textboxes invisible - then,
you can programmatically use the FindControl method in that particular row,
to find you data to validate against.

--
David Wier
MVP/ASPInsiderhttp://aspnet101.comhttp://iWritePro.com

"Mel" <MLights...@gmail.comwrote in message

news:11**********************@o61g2000hsh.googlegr oups.com...
I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:
gvParts.Rows(e.RowIndex).Cells(8).Text
Any help would be greatly appreciated.
Yuck, but I'll try anything at this point. So maybe I could add an
invisible drop-down box that is bound to the same AccessDataSource
that my GridView uses... Hmmm. I'll give it a whirl.
Thanks.

Jul 25 '07 #3
Server controls with Visible=false don't render to client and don't come
back on postbacks. A simple work around is to leave Visible=true and hide
the controls with css rule display:none.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Mel" <ML********@gmail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:

gvParts.Rows(e.RowIndex).Cells(8).Text
Any help would be greatly appreciated.

Jul 25 '07 #4
Mel,

It looks like your three column are the keys for the grid - you could
utilize built in functionality - DataKeyNames property (comma separated) -
and do not have to create columns for them.
then on the postback you can use DataKeys[e.RowIndex] - it will return your
three values

"Mel" wrote:
I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:

gvParts.Rows(e.RowIndex).Cells(8).Text
Any help would be greatly appreciated.

Jul 26 '07 #5
Mel
On Jul 25, 5:57 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Server controls with Visible=false don't render to client and don't come
back on postbacks. A simple work around is to leave Visible=true and hide
the controls with css rule display:none.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldin

"Mel" <MLights...@gmail.comwrote in message

news:11**********************@o61g2000hsh.googlegr oups.com...
I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:
gvParts.Rows(e.RowIndex).Cells(8).Text
Any help would be greatly appreciated.
Do you have an example of how to implement the display:none CSS rule?
I attempted it yesterday and I didn't see any difference; the columns
were still visible.

Mel
(Using Visual Studio 2005, Asp.net 2.0, Visual Basic, WinXP Pro SP2)

Jul 26 '07 #6
Sure, somethink like

<asp:BoundColumn DataField="MyField" >
<ItemStyle CssClass="Invisible"></ItemStyle>
<HeaderStyle CssClass="Invisible"></HeaderStyle>
</asp:BoundColumn>

and

..Invisible{display:none}

somewhere in styles.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mel" <ML********@gmail.comwrote in message
news:11*********************@e9g2000prf.googlegrou ps.com...
On Jul 25, 5:57 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>Server controls with Visible=false don't render to client and don't come
back on postbacks. A simple work around is to leave Visible=true and hide
the controls with css rule display:none.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldin

"Mel" <MLights...@gmail.comwrote in message

news:11**********************@o61g2000hsh.googleg roups.com...
I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:
gvParts.Rows(e.RowIndex).Cells(8).Text
Any help would be greatly appreciated.

Do you have an example of how to implement the display:none CSS rule?
I attempted it yesterday and I didn't see any difference; the columns
were still visible.

Mel
(Using Visual Studio 2005, Asp.net 2.0, Visual Basic, WinXP Pro SP2)

Jul 26 '07 #7
Mel
On Jul 26, 1:02 am, Sergey Poberezovskiy
<SergeyPoberezovs...@discussions.microsoft.comwrot e:
Mel,

It looks like your three column are the keys for the grid - you could
utilize built in functionality - DataKeyNames property (comma separated) -
and do not have to create columns for them.
then on the postback you can use DataKeys[e.RowIndex] - it will return your
three values

"Mel" wrote:
I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:
gvParts.Rows(e.RowIndex).Cells(8).Text
Any help would be greatly appreciated.
Okay cool. So now I can retrieve the 3 invisible fields using
DataKeys but how do I retrieve the contents of a Template field text
box (txtLength)? I tried FindControl but it always returns nothing,
maybe I'm using it wrong? The GridView control is in a table which is
on the Content1 section.
Jul 26 '07 #8
Mel
On Jul 26, 9:01 am, Mel <MLights...@gmail.comwrote:
On Jul 26, 1:02 am, Sergey Poberezovskiy

<SergeyPoberezovs...@discussions.microsoft.comwrot e:
Mel,
It looks like your three column are the keys for the grid - you could
utilize built in functionality - DataKeyNames property (comma separated) -
and do not have to create columns for them.
then on the postback you can use DataKeys[e.RowIndex] - it will return your
three values
"Mel" wrote:
I have 10 columns total. 3 of them are invisible. The rest are read-
only BoundFields, 3 of which are editable fields using
TemplateFields. Upon editing, I want to validate what the user enters
against one of those invisible columns. How do I accomplish this?
The code below that I attempted just returns an empty string when I
try to retrieve the invisible column data:
gvParts.Rows(e.RowIndex).Cells(8).Text
Any help would be greatly appreciated.

Okay cool. So now I can retrieve the 3 invisible fields using
DataKeys but how do I retrieve the contents of a Template field text
box (txtLength)? I tried FindControl but it always returns nothing,
maybe I'm using it wrong? The GridView control is in a table which is
on the Content1 section.
I figured it out. THANKS to everyone for your help! I explained what
I did to solve the problem below in case anyone else is interested.

Instead of attempting to retrieve Invisible column data (which doesn't
work upon PostBack) I removed the columns from the DataView and I used
the DataKeys property instead:
gvParts.DataKeys(e.RowIndex).Item("StretchOut")
gvParts.DataKeys(e.RowIndex).Item("NumBends")
gvParts.DataKeys(e.RowIndex).Item("SN")

To retrieve a template field in my GridView control I used the
FindControl method:
Dim txtLengthBox As TextBox =
gvParts.Rows(e.RowIndex).Cells(7).FindControl("txt Length")

The Entire Code is here:
Protected Sub gvParts_RowUpdating(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
gvParts.RowUpdating
Dim txtLengthBox As TextBox =
gvParts.Rows(e.RowIndex).Cells(7).FindControl("txt Length")
Dim CusVal As CustomValidator =
gvParts.Rows(e.RowIndex).Cells(7).FindControl("cvL ength")
If Trim(txtLengthBox.Text) <"120" And
gvParts.DataKeys(e.RowIndex).Item("StretchOut") = "48" And
gvParts.DataKeys(e.RowIndex).Item("NumBends") = "0" Then
'Do not allow the user to change the length of a sheet of
material. Sheets are always 120 inches in length.
CusVal.IsValid = False
txtLengthBox.Text = e.OldValues("Length")
e.NewValues("Length") = e.OldValues("Length")
Else
End If
End Sub

Jul 26 '07 #9
<asp:GridView ID="View_Applicants" runat="server"
AutoGenerateColumns="False" CellPadding="4" Font-Size="12pt"
ForeColor="#333333" GridLines="None" Width="360px">
<Columns>
<asp:BoundField DataField="Applicant_LName"
HeaderText="Last Name" />
<asp:BoundField DataField="Applicant_FName"
HeaderText="First Name" />
<asp:BoundField DataField="Applicant_Email"
HeaderText="Email" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#FF8000" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775"
/>
</asp:GridView>

*** Sent via Developersdex http://www.developersdex.com ***
Aug 9 '07 #10

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

Similar topics

6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
0
by: Mike N | last post by:
Using the Gridview control in ASP.NET i developed a a web form which displays general user information using simple databinding ad databound columns direct to a dataset. I wanted to hide my ID...
3
by: Rabbit | last post by:
Hi, I'm having a GridView with Datasource being set from CodeBehind method, its has a "RecID" databound field set as invisible. I want to utilize the "Delete" commandfield, so that on...
4
by: Curious Trigger | last post by:
Hi there, I have got a gridview showing a display-name of a person and keeping its person-id as value accessible. Now I am wondering how I can get to his age, if this field isn't visible in...
6
by: Greg | last post by:
Hello, I have a GridView bound to a custom object. I set the DataKeyNames property along with the column DataField properties at design time, and bind the GridView to my object at run-time. In...
5
by: bbawa1 | last post by:
I have a GetData methd which is returning a table using
2
by: rgparkins | last post by:
So, I've bitten the bullet and am converting some of my asp.net 1.1 sites to asp.net 2.0, now after many issues I have come to a stop with the objectdatasource and gridviews and maybe someone can...
2
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
Based on wether a row is selected in a GridView I need to HIDE the last two columns of a gridview. I do NOT need to make the cells invisible I want to hide the entire column. When I set the...
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: 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: 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...
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
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...

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.