开发者

GridView RowCount late update updatepanel

I have a gridview in an updatepanel where also my dropdownlist is. From the Trigger of the dropdownlist I am refreshing my gridview with the slected value. All that is working fine. The problem is that I am also displaying the gridview row count on the page which is also inside the updatepanel. The update seems to be happening to it, one selection too late.

protected void Drop_Change(object sender, EventArgs e)
{
    String Value = AjaxDrop.SelectedValue;
    GridView1.SelectParameters["Target"].Defaul开发者_如何学运维tValue=Value;
    RowCount.InnerText = GridView1.Rows.Count.ToString();
}

I think its happening one selection behind because the parameter updates the gridview rowcount too late for the RowCount value to have it, what is a work around to get the actual value after parameter passed. Only way I can think of is using javascript and I wonder if that would even work. My desired solution would be to keep it all on server side though.


At the time you're calling this, the GridView hasn't done it's databinding, therefore the value is not valid. Move your RowCount.InnerText updating to somewhere that gets executed after the DataBinding event (e.g. Page_OnPreRender), or force the DataBinding to occur before you update the row count.

It's worth noting that GridView.Rows.Count isn't a reliable source of information if you are using GridView paging - as this will be the number of rows on one page, even if there are more rows returned by the query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜