473,507 Members | 3,706 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_OnPageIndexChanged 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 7379
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.FindControl 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_OnPageIndexChanged 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...@discussions.microsoft.comwrote:
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_OnPageIndexChanged 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 OnpageIndexChanged for a
gridview or not but what I have below is for the
SelectedIndexChanged.

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource1"
OnSelectedIndexChanged="GridView1_SelectedIndexCha nged">
<Columns>
<asp:CommandField ShowSelectButton="true" />
<asp:TemplateField>
<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:TemplateField>
</Columns>
</asp:GridView>

Code Behind:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{
Label test =
(Label)GridView1.SelectedRow.Cells[0].FindControl("testId");
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...@discussions.microsoft.comwrote:
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_OnPageIndexChanged 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 OnpageIndexChanged for a
gridview or not but what I have below is for the
SelectedIndexChanged.

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource1"
OnSelectedIndexChanged="GridView1_SelectedIndexCha nged">
<Columns>
<asp:CommandField ShowSelectButton="true" />
<asp:TemplateField>
<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:TemplateField>
</Columns>
</asp:GridView>

Code Behind:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{
Label test =
(Label)GridView1.SelectedRow.Cells[0].FindControl("testId");
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
1814
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. ...
2
6530
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...
4
5337
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...
6
8244
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...
0
2374
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...
3
3521
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...
0
4330
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...
0
1718
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...
4
7211
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 -...
0
7313
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,...
1
7029
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...
0
7481
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...
0
5619
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,...
1
5039
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
4702
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...
0
3190
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
1537
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 ...
0
411
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...

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.