473,662 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview hidden label value

Hello all,
I have a gridview, and a label inside the <Columnsand ItemTemplate. The
label is a hidden. I want to retrieve the value of this label on the
gridview_OnPage IndexChanged event, but i seem to get a nullexception. Can
anyone please tell me what iam doing wrong.

When i do the "view source" option i do see the values in the label.
thanks for all the help

May 25 '07 #1
3 7394
Hello Smita,

Can u demonstrate how u do this?
Generally the process is
1) Open the page source code, and make sure that your hidden control exist
in code.
2) using the Page.FindContro l Grid->Row->Item u can get access to your hidden
control

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

SHello all,
SI have a gridview, and a label inside the <Columnsand
SItemTemplate. The
Slabel is a hidden. I want to retrieve the value of this label on the
Sgridview_OnPag eIndexChanged event, but i seem to get a nullexception.
SCan anyone please tell me what iam doing wrong.
S>
SWhen i do the "view source" option i do see the values in the label.
Sthanks for all the help
S>
May 25 '07 #2
On May 25, 10:47 am, Smita <S...@discussio ns.microsoft.co mwrote:
Hello all,
I have a gridview, and a label inside the <Columnsand ItemTemplate. The
label is a hidden. I want to retrieve the value of this label on the
gridview_OnPage IndexChanged event, but i seem to get a nullexception. Can
anyone please tell me what iam doing wrong.

When i do the "view source" option i do see the values in the label.
thanks for all the help
I am not sure if there is an event called OnpageIndexChan ged for a
gridview or not but what I have below is for the
SelectedIndexCh anged.

<asp:GridView ID="GridView1" runat="server"
AutoGenerateCol umns="False" DataKeyNames="I D"
DataSourceID="S qlDataSource1"
OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged">
<Columns>
<asp:CommandFie ld ShowSelectButto n="true" />
<asp:TemplateFi eld>
<ItemTemplate >
<asp:Label ID="test2" runat="server"
Text='<%# Bind("id") %>' ></asp:Label>
<asp:Label ID="testId" runat="server"
Text='<%# Bind("type") %>' Visible="true" ></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>

Code Behind:
protected void GridView1_Selec tedIndexChanged (object sender, EventArgs
e)
{
Label test =
(Label)GridView 1.SelectedRow.C ells[0].FindControl("t estId");
Response.Write( test.Text);
}

You should be able to apply to your other gridview event. This is
assumed that there is a row selected on the gridview.

May 25 '07 #3
Thank you for all the quick response.. i got it working, mistake on my side
was that the label was declared outside on page load and hence the object
value was never set which got me a nullpointer exception.
-
S

"Nesster13" wrote:
On May 25, 10:47 am, Smita <S...@discussio ns.microsoft.co mwrote:
Hello all,
I have a gridview, and a label inside the <Columnsand ItemTemplate. The
label is a hidden. I want to retrieve the value of this label on the
gridview_OnPage IndexChanged event, but i seem to get a nullexception. Can
anyone please tell me what iam doing wrong.

When i do the "view source" option i do see the values in the label.
thanks for all the help

I am not sure if there is an event called OnpageIndexChan ged for a
gridview or not but what I have below is for the
SelectedIndexCh anged.

<asp:GridView ID="GridView1" runat="server"
AutoGenerateCol umns="False" DataKeyNames="I D"
DataSourceID="S qlDataSource1"
OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged">
<Columns>
<asp:CommandFie ld ShowSelectButto n="true" />
<asp:TemplateFi eld>
<ItemTemplate >
<asp:Label ID="test2" runat="server"
Text='<%# Bind("id") %>' ></asp:Label>
<asp:Label ID="testId" runat="server"
Text='<%# Bind("type") %>' Visible="true" ></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>

Code Behind:
protected void GridView1_Selec tedIndexChanged (object sender, EventArgs
e)
{
Label test =
(Label)GridView 1.SelectedRow.C ells[0].FindControl("t estId");
Response.Write( test.Text);
}

You should be able to apply to your other gridview event. This is
assumed that there is a row selected on the gridview.

May 25 '07 #4

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

Similar topics

0
1821
by: Lee Moore | last post by:
I have the following code, which I thought should work. I get an error stating ... Could not find control 'GOAL_TEXT_CONTROL' in ControlParameter 'GOAL_TEXT'. Any help would be great. <-------------------------- Code Snippet ---------------------------> <asp:GridView ID="GridView1" Runat="server"
2
6544
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row *that is going to be deleted* into another table, before the original data is deleted. I am trying to use the RowDeleting method to call an Update or Insert
4
5341
by: GregG | last post by:
Greetings, I have been working with the new GridView control, and while figuring out most of it's idiosyncrasies on my own, have stumbled upon a problem I cannot seem to resolve. We have table displayed in a GV control. It allows for editing and selecting, etc. Some of the fields are 60 characters long, but only the first 20 or so are relevant, and all of them have to fit on one line within the row -
6
8262
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im trying to load the ddl with a list of dates from another table keyed on GridView row field that only apply to this row. Any suggestions would be appreciated.
0
2385
by: Mike P | last post by:
Where exactly are the updateparameters of a gridview picked up from? I have created 2 very similar gridviews and given the updateparameters the same names as in my edititemtemplates. Yet this method has worked for 1 gridview and failed for the second gridview. Here is my gridview : <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XConnectionString %>" SelectCommand="ViewForecast"...
3
3547
by: Gunawan | last post by:
Dear All, I have data which display on the GridView. GridView contain 3 Column (ProductId, ProductCode and Description). I would like to display only Product Code and Description so I hide ProductId Column. Is there any command so I can take value of first column which is Product ID? In other words, how can I get value from hidden column on Grid View? TIA,
0
4339
by: troyblakely | last post by:
I have a gridview which is pulling data from a SqlDataSource, the select command queries a view and the update command is a stored procedure. I'm using a stored procedure because several tables need to be updated based on the data in the gridview. <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:slightsInventoryConnectionString %>" SelectCommand="SELECT * FROM " UpdateCommand="upd_Inventory"...
0
1739
by: =?Utf-8?B?cGI2NDgxNzQ=?= | last post by:
We have been having this problem for months and always assumed it was because of our somewhat complicated setup. I have just spent almost all of today making this into a simple example that can be easily reproduced and it seems like a major .NET flaw/limitation that I was hoping you could explain to me as it is really frustrating me. I just want to be able to get info for a row clicked, whether it is a Repeater, GridView, etc. I have...
4
7239
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which - "Modified" of type DateTime - is hidden since it should not be edited by a user. The system handles the update for this column. So, I have hidden (Visible=false) this column on the grid. In order to access the value in this field, I have created a...
0
8435
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
8857
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
8768
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
7368
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
6186
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
5655
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
4181
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...
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1754
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.