2
votes

i hope someone can help! i have a user control that has a gridview (there is an update panel in the UC)

i'm using this UC on 2 different pages - on both pages, the UC is on a tab (ajax tabpanel) with the tab being inside an update panel.

on 1 page, when i use the .DataBind() (not initial load), it fires the RowDataBound event and the grid is completed correctly.

BUT on the 2nd page (SAME EXACT CODE!!), the .DataBind does NOT fire the RowDataBound event and the datasource is not bound/refreshed. any ideas why this would happen?

3

3 Answers

3
votes

The RowDataBound event only fires when the GridView's data changes during the postback. The event is short-circuited for speed so it's not re-generating the exact same data unnecessarily. Use the RowCreated event to manipulate the HTML instead - it fires on every postback regardless of whether the data has changed.

0
votes

First check if you have caching enabled (on the server). I would also use break points to trace whether the application gets into the Page_Load event at all.

If your caching is enabled, the browser will cache and not use Page_Load, and consequently not use DataBind().

hope this helps

0
votes

I have got resolved by putting the line of code

(TabContainer1_ActiveTabChanged(TabContainer1, null);) 

in Page_Load event, not in !IsPostback event

protected void Page_Load(object sender, EventArgs e)
    Page.Title = ConfigurationManager.AppSettings["PageTitle"].ToString().Trim() + " Project Type";

    if (!IsPostBack)
    {
        if (Request.Params["stidx"] != null && Request.Params["stidx"].ToString().Trim() != "")
        {
            if (Request.Params["stidx"].ToString().Trim() == "0")   //have to make project type selected in left
            {
                NullAllDate_Except_ProjectType();

                TabContainer1.ActiveTabIndex = 0;

                LeftBar.var_data_to_show = "";
            }
            else if (Request.Params["stidx"].ToString().Trim() == "1")   //have to make Modules selected in left
            {
                NullAllDate_Except_Module();

                TabContainer1.ActiveTabIndex = 1;

                LeftBar.var_data_to_show = "";
            }
            else if (Request.Params["stidx"].ToString().Trim() == "2")   //have to make Activity selected in left
            {
                NullAllDate_Except_Activity();

                TabContainer1.ActiveTabIndex = 2;

                LeftBar.var_data_to_show = "";
            }
            else if (Request.Params["stidx"].ToString().Trim() == "3")   //have to make Systems selected in left
            {
                NullAllDate_Except_Systems();

                TabContainer1.ActiveTabIndex = 3;

                LeftBar.var_data_to_show = "";
            }
            else if (Request.Params["stidx"].ToString().Trim() == "4")   //have to make Module Headers selected in left
            {
                NullAllDate_Except_ModuleHeaders();

                TabContainer1.ActiveTabIndex = 4;

                LeftBar.var_data_to_show = "";
            }
            else
            {
                NullAllDate_Except_ProjectType();

                LeftBar.var_data_to_show = "";
            }
        }
        else
        {
            NullAllDate_Except_ProjectType();

            LeftBar.var_data_to_show = "";
        }

    }

    if (IsPostBack)
    {
        if (MyScriptManager.IsInAsyncPostBack)
        {
            //LeftBar.var_data_to_show = true;
            LeftBar.var_data_to_show = GetModuleName(TabContainer1.ActiveTabIndex.ToString());
        }
    }

    TabContainer1_ActiveTabChanged(TabContainer1, null);    //this is required here, otherwise onrow databound is not working on !Postback
}