473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

GridView Questions

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 event in GridView? I thought it
would be RowCommand, but I can't get that event to fire with a check box
field that I drag/drop in a template column in the ItemTemplate.

2.) For a Templated column, like a check box above, where do I tell it the
data field to bind from the data source? There is not a Template DataField
property to set to the database field name as in a bound field.
--
Chris Davoli

Aug 5 '06 #1
4 6698
Hi,

first of all, DataGrid still exists in ASP.NET 2.0, so you can use it also.
But the replies:

1) RowCommand is the equivalent. CheckBox doesn't raise ItemCommand event
since it doesn't provide CommandName and CommandArgument
attributes/properties to apply event bubbling which raising
ItemCommand/RowCommand basically is (it doesn't raise it in ASP.NET v1.1
either). By default only Button, ImageButton or ImageButton (=IButtonControl
interface) or the built-in command columns/fields also raise correspondiong
event in GridView. Can you show an exa,ple what you want to do,.or how you
have done it in v1.1?

2) You would use a databinding expression as in v1.1. For example
<%#Eval("FieldName") %within <ItemTemplate>...</ItemTemplate>. Tenplate
field is templated and setting the layout etc is in developer's hands so
having datafield for it wouldn't make sense.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Chris Davoli" <Ch*********@discussions.microsoft.comwrote in message
news:2E**********************************@microsof t.com...
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 event in GridView? I thought
it
would be RowCommand, but I can't get that event to fire with a check box
field that I drag/drop in a template column in the ItemTemplate.

2.) For a Templated column, like a check box above, where do I tell it the
data field to bind from the data source? There is not a Template DataField
property to set to the database field name as in a bound field.
--
Chris Davoli

Aug 5 '06 #2
Hello Chris,
The equavalent of ItemCommand in GridView is RowCommand.
What I understood from your question part (1) is you added a checkbox to a
templated field in your GridView, and you set AutoPostBack to true and
implemented RowCommand event, and when executing the event is not firing?!
Well this will not work also in DataGrid. So you can impelement selectChange
Event of your CheckBox Instead. Hope I hit your idea in this.

About the second part,
You want to bind a DataSource Field to your CheckBox located in your
GridView Templated Field, Well, Select your CheckBox and note the smart tag
icon in the top right. click on it and you will get Edit DataBindings link.
click on too and start do what you want.

Regards,
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"Chris Davoli" wrote:
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 event in GridView? I thought it
would be RowCommand, but I can't get that event to fire with a check box
field that I drag/drop in a template column in the ItemTemplate.

2.) For a Templated column, like a check box above, where do I tell it the
data field to bind from the data source? There is not a Template DataField
property to set to the database field name as in a bound field.
--
Chris Davoli
Aug 5 '06 #3
Thanks for the ideas. They may help, but here is more of what I need.

For #1:
If I use the selectChange event to check the check box, how do I tell which
row the check box was checked (multiple rows in the gridview)? Also, how do I
get say another field ie a unique Index to be used for DB calls etc.?

For #2:
I found the smart tag(Edit Data bIndings), but it is not enabled. Binding
for Checked fields below it are all disabled. I see the fields, but they are
disabled. Only the custom binding is enabled. How do I enable the bindings?
--
Chris Davoli

"Muhammad Mosa" wrote:
Hello Chris
The equavalent of ItemCommand in GridView is RowCommand.
What I understood from your question part (1) is you added a checkbox to a
templated field in your GridView, and you set AutoPostBack to true and
implemented RowCommand event, and when executing the event is not firing?!
Well this will not work also in DataGrid. So you can impelement selectChange
Event of your CheckBox Instead. Hope I hit your idea in this.

About the second part,
You want to bind a DataSource Field to your CheckBox located in your
GridView Templated Field, Well, Select your CheckBox and note the smart tag
icon in the top right. click on it and you will get Edit DataBindings link.
click on too and start do what you want.

Regards,
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"Chris Davoli" wrote:
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 event in GridView? I thought it
would be RowCommand, but I can't get that event to fire with a check box
field that I drag/drop in a template column in the ItemTemplate.

2.) For a Templated column, like a check box above, where do I tell it the
data field to bind from the data source? There is not a Template DataField
property to set to the database field name as in a bound field.
--
Chris Davoli
Aug 6 '06 #4
For #1:
a)Implement RowDataBound of your GridView as the following:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView row = (DataRowView)e.Row.DataItem;
CheckBox chk = (CheckBox)e.Row.FindControl("CheckBox1");
chk.Attributes["CustomValue"] = row["ProductID"].ToString();
}
}
Note that I have added CustomValue attribute to everu check box with datakey
value stored in it.
b)Now Implement selectChanged event of your checkbox but don't forget to set
autopostback to true
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
string s = ((CheckBox)sender).Attributes["CustomValue"];
}

For #2
in the custom binding area, add Eval("YourDataFieldName") or
Bind("YourDataFieldName")

Hope this would help
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
Aug 6 '06 #5

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

Similar topics

4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
0
by: Maarten | last post by:
Hi all, I have a datagrid (GridView) with questions where the user has to make a choice (yes or no questions) But for some questions there are rules, like if you choose (yes or no) for some...
1
by: JasonK | last post by:
I would like to move the Delete button such that it displays one time in the footer row, rather than on every row. I've seen lots of questions asked on the subject around the net, but no answer...
4
by: VMI | last post by:
I'm working on a questionaire, and I'd like to add the questions to a gridview, so that each row (of two "columns" each) has the question in one field, and the editable section (where the user will...
8
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the wizards. Basically working as expected. The...
1
by: jmdolinger | last post by:
Hi all, I'm a newbie to Atlas (and recently ASP.NET) after coming from a long Java background, also have done quite a bit with an Ajax.NET/ASP.NET 1.1 project, but it was basically all...
1
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but...
5
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are...
4
by: Peter | last post by:
I want to call a JavaScript on PageIndexChanged event, how do I do that? Thank You Peter
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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
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
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
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
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
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
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...

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.