gridview databind only works sometimes

gridview databind only works sometimes

am 15.01.2008 16:30:03 von rlm

I have standard gridview in an updatePanel with an AJAX timer that refreshes
the data every 5 seconds by calling the grids DataBind method in the tick
event. This works great.

However, I have a checkbox on the web page which when checked I want to hide
some rows. The code that does the hiding is in the RowDataBound event where I
do a bunch of other stuff. This way every time the data is updated the rows
are correctly displayed or hidden. And that code works on the 5 second
updates, but when they click the checkbox I don't want them to have to wait 5
seconds. But in the server side click event of the check box when it call the
grid's DataBind() event, it either doesn't work, or at least it never
executes my RowDataBound event code like it does when the time calls it.

Any ideas why DataBind works from the Timer_Tick and not the checkbox click?

RE: gridview databind only works sometimes

am 15.01.2008 22:38:04 von mily242

Hi there,

It should look similar to the following code:

-- begin aspx code --

ChildrenAsTriggers="true">





<%# DateTime.Now.Ticks %>










Interval="5000" />
OnCheckedChanged="checkBox_CheckedChanged" />
-- end aspx code --

-- begin c# code beside --

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}

private void BindData()
{
// use the checkbox's value
gv.DataSource = new int[5];
gv.DataBind();
}
protected void checkBox_CheckedChanged(object sender, EventArgs e)
{
BindData();
}
protected void timer_Tick(object sender, EventArgs e)
{
BindData();
}
-- end c# code beside --

hope it helps
--
Milosz


"rlm" wrote:

> I have standard gridview in an updatePanel with an AJAX timer that refreshes
> the data every 5 seconds by calling the grids DataBind method in the tick
> event. This works great.
>
> However, I have a checkbox on the web page which when checked I want to hide
> some rows. The code that does the hiding is in the RowDataBound event where I
> do a bunch of other stuff. This way every time the data is updated the rows
> are correctly displayed or hidden. And that code works on the 5 second
> updates, but when they click the checkbox I don't want them to have to wait 5
> seconds. But in the server side click event of the check box when it call the
> grid's DataBind() event, it either doesn't work, or at least it never
> executes my RowDataBound event code like it does when the time calls it.
>
> Any ideas why DataBind works from the Timer_Tick and not the checkbox click?