views:

35

answers:

1

In the ItemDataBound handle i set backgroud color to some items:

protected void MyDataList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                TextBox cellTextBox = (TextBox)e.Item.FindControl("CellTextBox");

                if (...)
                {
                    e.Item.BackColor      = Color.LightSkyBlue;
                    cellTextBox.BackColor = Color.LightSkyBlue;
                }
            }
        }

But after postback (when DataBind for MyDataList doesn't call) color of the inner textBox is same, but color of entire item resets. What is the correct way to set the color for the entire item?

A: 

I've try to handle onPreRender event of the textbox instead of setting color on IemDataBound event, but background color just disappears:

<script  language="javascript">
function SetItemColor(cell)
{
    var color = "#87CEFA";
    cell.style.backgroundColor = color;
    cell.parentNode.style.backgroundColor = color;
}
</script>


protected void MyDataList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                TextBox cellTextBox = (TextBox)e.Item.FindControl("CellTextBox");

                if (...)
                {
                   cellTextBox.Attributes.Add("onPreRender", "SetItemColor(this);");
                }
            }
        }

Whats wrong?

PS. DataBind() for the DataList doesn't called if postback:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                DataBind();
        }
Sevina
As i understand, onPreRender client event sholud raises there was postback, wasn't it?
Sevina
It seems no client events raise on nested controls of DataList after postback (submit button click)... :(
Sevina