473,654 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem: RowCommand Event - GridView.FindCo ntrols

87 New Member
Hi,

I have a gridview in my web page. I have boundcolumn,che ckboxcolumn 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 7941
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.Select edIndexChanged Event instead?

Is the checkbox available at the time when you are trying retrieve the checkbox?
For example, if the checkbox is in the EditItemTemplat e 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 SelectedIndexCh anged 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(in dex).controls.a dd(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
1327
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 error, I have proved this by having it use a streamwriter to create and write to a simple text file after raising the event. Twenty-five files are created each time the button is pressed. The form is wired up to the event (rr.OnComplete += new...
1
2294
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, GridViewCommandEventArgs e) { if (e.CommandName == "OpportunityDetails")
1
2465
by: keithb | last post by:
What causes a GridView RowCommand Event to intercept a RowDeleting Event? How to cure it? Thanks, Keith
6
28132
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 RowDataBound event to set the commandargument of the delete button. The event is being fired and works fine. When I press the delete button, the RowCommand event is not firing! and neither is the RowDeleting (the button's commandName is...
0
1341
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 get the rownumbers. I don't know what the reason could be. But for some reason I need to use Template column <Asp:buttonhow can I get the rownumbers in Gridview in RowCommand event?
1
25652
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 http://www.developersdex.com ***
7
17311
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 either! Does anyone know how can I make this work? Thanks in advance!
1
2853
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, but I cant seem to find a solution to it in terms of a fix, or explaination as to why. Any ideas here ?
0
1869
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 problem is that the event handler hasn't been set when I check it in the GridView RowCommand event, i.e. if (btnSelectRecordHandler != null) ...
0
8375
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
8815
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
8707
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
8593
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6161
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
4149
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...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1593
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.