wawang
6/28/2007 9:46:00 AM
Hi Chuck,
You might have noticed that GridView's CommandField can dynamically
show/hide various buttons:
protected void Page_Load(object sender, EventArgs e)
{
foreach (DataControlField dcf in GridView1.Columns)
{
CommandField cf = dcf as CommandField;
if (cf != null)
{
cf.ShowEditButton = CheckBox1.Checked;
break;
}
}
Internally, whenever a DataControlField is changed, GridView will set a
flag RequiresDataBinding and calls DataBind again if needed.
To fix HotGridView.cs:
public bool AutoGenerateCheckBoxColumn
{
get
{
object o = ViewState["AutoGenerateCheckBoxColumn"];
if (o == null)
return false;
return (bool)o;
}
set {
if (AutoGenerateCheckBoxColumn != value)
{
ViewState["AutoGenerateCheckBoxColumn"] = value;
if (base.Initialized)
{
base.RequiresDataBinding = true;
}
}
}
}
(Note the sample code has some bug in OnPreRender, it should check whether
or not FindControl returns null value)
With above change, you will be able to use code like this to dynamically
show/hide the checkBox column:
GridView1.AutoGenerateCheckBoxColumn = CheckBox1.Checked;
Hope this helps.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.