473,489 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Gridview Rowcommand / Rowcreated question

Hi,

I've got a gridview that I bind programmatically to a view of a typed
dataset. One column has a command button, and in the RowCreated event, I test
to see if it's a DataRow, and if it is, I grab the button and attach a value:

{
Response.Write("<br/>" + e.Row.Cells[1].Controls[0].ToString() +
"<br/>");
// Retrieve the LinkButton control from the first column.
Button addButton = (Button)e.Row.Cells[1].Controls[0];

// Set the LinkButton's CommandArgument property
addButton.CommandArgument =
((DataRowView)e.Row.DataItem)["RowID"].ToString();

}

}

This works fine when the page loads (and I see the response.write). When I
click the button for a row, however, I get a null reference exception, not in
the RowCommand handler but in the RowCreated handler (likely because my data
source is not persisted, and I'm not refreshing my dataset from the database
or grabbing it from viewstate on postback - i didn't expect RowCreated to
fire again).

As a test, I replaced the line

addButton.CommandArgument = ((DataRowView)e.Row.DataItem)["RowID"].ToString();
with:
addButton.CommandArgument = Convert.ToString(1);

I expected to get around the null reference error, which I did, but now, I
didn't get the response.write! This seems to indicate that with this change,
it didn't even fire the RowCreated event when it was doing the RowCommand,
which it seemed to when I was getting the null reference exception.

So: when a rowcommand is fired, is a rowcreated event fired also? Is this
based on some condition? (I don't do any rebinding on postback)

Thanks for any help for this foggy situation.

-Ben
Feb 29 '08 #1
0 2633

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

Similar topics

1
9097
by: Zule | last post by:
Hi, I am creating a Composite Control within which I have a GridView. In this GridView, I have three TemplateFields, the last one being a template with a LinkButton which is meant to be clicked...
1
2638
by: Melanie Peterson | last post by:
What's the equivalent in GridView of the DataGrid e.Item.Cells(2).Text (where e is DataGridCommandEventArgs)? Thanks much
4
6707
by: Chris Davoli | last post by:
I've got two questions on how to do things in the new GridView. I'm used to the DataGrid in ASP 1.1, so I need the equavalent in ASP 2.0 Gridview. 1.) What is the equavalent for Item Command...
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...
2
6014
by: David | last post by:
I have a template field in a GridView that contains two ImageButtons. When the user clicks one of the buttons, the GridView's RowCommand event is fired and I can get the CommandName. All that is...
0
2101
by: Kyle K. | last post by:
(Note: Windows XP Pro SP2 + Visual Studio .NET 2005 + SQL Server 2000) I have a GridView that is populated with data. That last 2 columns are button fields (image buttons) that have a CommandName...
2
48394
by: cartmann | last post by:
Hi, I have a gridview with a template column. In the template column i have two commandbuttons. When clicking the buttons I enter the cmd_click event - but how do I read in which row the button...
4
4177
by: chris | last post by:
I have a perent gridview which includes in a template field a child gridview. Child gridview includes command buttons for opening different windows based on its row selected. I used the code...
0
1031
by: | last post by:
I am using radiobuttons in a gridview, and not a column of radiobuttons. I have one cell in each row with several radiobuttons that the user has to choose a radiobutton within each row. How can I...
0
7108
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
6967
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
7142
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
7352
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
5445
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,...
0
4565
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
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
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
272
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.