开发者

How to Reload the page after Datalist Databind

Asp.net with c#

i am using 16 datalist asp.net controls in my page I have programatically defined each updated command as below:

protected void DataList1_UpdateCommand(object source,
        DataListCommandEventArgs e)
    {

        //This codes repeats for all 16 datal开发者_Python百科ist , diferent naming controls such as DataList2, Datalist3, etc.....


        String categoryID = DataList1.DataKeys[e.Item.ItemIndex].ToString();
        String dp_status = ((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue;
        //String txt_dept = 


        SqlDataSource1.UpdateParameters["Id"].DefaultValue = categoryID;
        SqlDataSource1.UpdateParameters["Status"].DefaultValue = dp_status;
        // SqlDataSource1.UpdateParameters["Comment"].DefaultValue = ;
        //  SqlDataSource1.UpdateParameters["Census"].DefaultValue = ;

        SqlDataSource1.Update();

        DataList1.EditItemIndex = -1;
        DataList1.DataBind();

    }

 protected void DataList_ItemDataBound(object sender, DataListItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item ||
          e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView drv = (DataRowView)(e.Item.DataItem);

            string status = drv.Row["Status"].ToString();
            if (status == "Available")
                e.Item.BackColor = System.Drawing.Color.LightGreen;
            if (status == "Assigned")
                e.Item.BackColor = System.Drawing.Color.LightSteelBlue;
            if (status == "BR")
                e.Item.BackColor = System.Drawing.Color.LightSalmon;

        }

    }//End Nt1 Change Colors

The problem is that once I update a datalist I loose the color change in my other Datalist controls.... Is there any way I can have all datalist rebind? or page reload after updating a record in any datalist?

If i insert new row / update exciting row, delete a row means automatically the gridview have to refresh. what i have to do//?....


During a postback the ItemDataBound event does not re-fire if .DataBind() is not being called. When your items are loaded from viewstate/controlstate no ItemDataBound results in no coloration.

At first cut I would remove your Item_DataBound as you have it and create a routine that iterates through each of the lists and sets the desired color. I would invoke this on pre-render.

Another choice would be to use jquery/javascript on the client once the page is loaded to do basically the same thing using styles and css.

You might get the result you want wrapping each list in an ajax 'update panel' but that will bloat your page and cost you on performance.


You can put that DataList section of your page inside an update panel like:

 <asp:ScriptManager runat="server"/> 

 <asp:UpdatePanel runat="server">
       <contentTemplate>

          <!--  Your content Here -->

       </contentTemplate>
 </asp:UpdatePanel>  

This should definitely solve your problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜