How to Reload the page after Update (Datalist Databind)

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 datalist , 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?

f i insert new row / update exciting row, delete a row means automatically the gridview have to refresh. what i have to do//?....
LVL 9
TonyRebaAsked:
Who is Participating?
 
Alfred A.Connect With a Mentor Commented:
It is up to you where you want to do a page reload.  However, if you want to refresh after a databind, you could do it something like this (I am assuming your page name is samepage.aspx as an example):


protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e) {

    //This codes repeats for all 16 datalist , 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();

    Response.Redirect("SamePage.aspx");

}
0
 
Alfred A.Commented:
For page reload, you could try doing a Response.Redirect("samepage.aspx"); to the same page to force a page reload/postback.

Or, you could use AJAX to do partial updates on the datalist that needs to be refreshed. Check the link below:

http://www.asp.net/ajax/tutorials/understanding-partial-page-updates-with-asp-net-ajax
0
 
havj123Commented:
If you have 16 datalist on single page and you are changing row color on one datalist ItemDataBound event then how can others datalist row color can change as ItemDataBound events fire on the updated datalist. Try find datalist control by ID in this event and test it.

Else Response.Redirect to same page
0
 
TonyRebaAuthor Commented:
Where. Do I place the redirect t
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.