Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView Questions

Reply
Thread Tools

GridView Questions

 
 
=?Utf-8?B?Q2hyaXMgRGF2b2xp?=
Guest
Posts: n/a
 
      08-05-2006
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

 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      08-05-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?TXVoYW1tYWQgTW9zYQ==?=
Guest
Posts: n/a
 
      08-05-2006
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
>

 
Reply With Quote
 
=?Utf-8?B?Q2hyaXMgRGF2b2xp?=
Guest
Posts: n/a
 
      08-06-2006
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
> >

 
Reply With Quote
 
=?Utf-8?B?TXVoYW1tYWQgTW9zYQ==?=
Guest
Posts: n/a
 
      08-06-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
GridView in a GridView Carlos Albert ASP .Net 2 12-06-2005 12:42 PM
GridView in a GridView Nalaka ASP .Net 6 12-05-2005 05:48 PM
Gridview with combobox whose data is dependent on field in gridview wallermj@hotmail.com ASP .Net 3 11-21-2005 05:34 PM
Re: Questions....questions....questions Patrick Michael A+ Certification 0 06-16-2004 04:53 PM



Advertisments