Gridview Questions

C

Chris Davoli

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.
 
A

Alessandro Zifiglio

hi Chris, Checkbox control does not fire a command Event so you are out of
luck here. Nothing will be fired in the RowCommand method. Your alternative
is to wire the checkedchanged event declaratively on the checkbox control
itself like :

<asp:CheckBox ID="CheckBox1" runat="server"
OnCheckedChanged="CheckBox1_CheckedChanged" />

the method it is wired to :

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{

}

As for your second question, do it as you did in asp.net 1.1. Add the
checkbox to the itemtemplate, and call a method in your codebehind that
returns true or false, based on the value of the datafield.
Alternatively, following is a proper example on how to include a checkbox in
a datagrid control using custom templates, the same style will apply to the
gridview as well. Small minor changes on how to hookup the custom checkbox
template, but nothing you cant find answers to on google or postback here
with problems.
http://support.microsoft.com/kb/306227/

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top