473,503 Members | 4,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem: RowCommand Event - GridView.FindControls

87 New Member
Hi,

I have a gridview in my web page. I have boundcolumn,checkboxcolumn and a linkbutton column.

The commandName of the linkbutton column is "Select"

The name of the template checkbox is "chkSwapSelect".

I want to check the checkbox of the linkbutton clicked row.

When i click the linkbutton of the gridview RowCommand Event fires

RowCommand Event Code:
Expand|Select|Wrap|Line Numbers
  1. if e.commandName="Select" then
  2.  Dim index as integer=Integer.Parse(e.CommandArgument)
  3.  Dim row as GridVIewRow=dgvAllocation.rows(index)
  4.  dim chk as checkbox
  5.  chk=new checkbox
  6.  chk=ctype(row.FindControl("chkSwapSelect"),checkbox)  // chk returns nothing
  7.  chk.checked=true // object reference not set to an instance of the object
  8. end if
The errors are shown as comments in the above code.

Please help me in finding the controls inside a gridview via RowCommand Event
Mar 19 '10 #1
8 7925
Ananthu
87 New Member
Please reply me quickly...

I am struggling with this task.
Mar 19 '10 #2
liawcv
33 New Member
---------- Reply Deleted ----------
NOTE: Just realized your are using dynamic column. My suggestion may not work... :p
Mar 19 '10 #3
Ananthu
87 New Member
Please give me the solution for it.
Mar 19 '10 #4
Frinavale
9,735 Recognized Expert Moderator Expert
Ananthu,

Have you tried stepping through your application to make sure that the correct selected index is being used?

Have you considered using the GridView.SelectedIndexChanged Event instead?

Is the checkbox available at the time when you are trying retrieve the checkbox?
For example, if the checkbox is in the EditItemTemplate and is not located in the ItemTemplate then the checkbox is only available if the GridView is in edit mode....it is not available if the GridView is not in edit mode.

-Frinny
Mar 19 '10 #5
Ananthu
87 New Member
Hi,

I have tried with SelectedIndexChanged Event also. But the same error: Object reference not set to an instance of the object appears to me.

I haven't tried with GridView Edit mode. Can you please tell me the procedures
for it and where i have to place my code for checking the checkbox in gridview.

Any solution for this issue. Please give me.
Mar 19 '10 #6
Frinavale
9,735 Recognized Expert Moderator Expert
Please post the ASP.NET markup for the column that contains the checkbox.

What I want to see is something that looks like this:
Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateField>
  2.   <ItemTemplate>
  3.     <!-- stuff -->
  4.   </ItemTemplate>
  5.   <EditItemTemplate>
  6.     <!-- stuff -->
  7.   </EditItemTemplate>
  8.   <!-- etc -->
  9. </asp:TemplateField>
You can find this by viewing the ASPX code [Source].
Please just post the TemplateField item that contains the checkbox.

Thanks

-Frinny
Mar 19 '10 #7
Ananthu
87 New Member
Hi,

I am not creating the gridview columns in design mode.

I am creating them at runtime when i click the submit button only.

I need it like that. This only creates the problem of not finding the control in gridview it seems.

But i know that in page_preinit event, when i create dynamic grid, there is no problem in finding dynamic controls by a button click.

Please provide me the solution. I want to create dynamic gridview columns after a button click only and find the controls in it. This is my requirement.

Please help me.
Mar 20 '10 #8
Ananthu
87 New Member
Hi,

I found the answer atlast for this issue.

To resolve the error Object reference not set to an instance of the object, again we have to write codings for finding the checkbox controls in gridview in RowCreated event of gridview. If the control is not found means we have to add the checkbox control again in the rows by using,

e.rows.cells(index).controls.add(chk)

Now i am able to find checkbox control after selecting the linkbutton in the gridview.

Thanks for trying out my issue to this extent.
Mar 21 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1318
by: Tim Gallivan | last post by:
Hi group, I'm having a strange problem with event handling. My project has a form with a textbox that creates 25 instances of class A when a button is clicked. Class A raises the event without...
1
2283
by: Mike P | last post by:
I have a ButtonField in my GridView with a CommandName, and I have a method which I am using to capture each click of the button : protected void GridView1_RowCommand(object sender,...
1
2458
by: keithb | last post by:
What causes a GridView RowCommand Event to intercept a RowDeleting Event? How to cure it? Thanks, Keith
6
28099
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
0
1334
by: mesut | last post by:
hit there, I have a problem getting the rownumbers when I use the template field <asp:button control. I don't get the rownumbers when I use this control. When I use a buttonfield control then I...
1
25640
by: Muhammad Saad Abbasi | last post by:
Hello, I have a problem that I may not be able to get the row index in template column in grid view. Can anyone help me for this problem. *** Sent via Developersdex...
7
17301
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work...
1
2823
by: Just Me | last post by:
I have discovered a( nd its probably not news to most of you ) that if you add a button column and use the Image Button type that this event fires twice. I know its been reported about a year ago,...
0
1854
by: progman417 | last post by:
Hello, I've got a Web User Control containing a gridview with a "select record" button on each row. When the user clicks the button I want to call an event handler in the main page. My...
0
7193
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
7067
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
7316
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...
1
6975
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
5562
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
4992
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
4666
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
3160
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
371
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.