Reputation: 2647
I have a RadGrid bound to SqlDataSource. All items are always in edit mode.
protected void RadGPozycje_PreRender(object sender, EventArgs e)
{
for (int i = 0; i < RadGPozycje.PageSize; i++)
{
RadGPozycje.EditIndexes.Add(i);
}
RadGPozycje.Rebind();
}
When bound, my cell "Vat" should change value to "zw" when value from database is equal to -1. I tried to do this like that:
private void RadGPozycje_ItemDataBound(object sender, GridItemEventArgs e)
{
GridDataItem item;
item = e.Item as GridDataItem;
if (item["Vat"].Text == "-1")
item["Vat"].Text = "zw";
}
and it doesn't work. How can I do this so it will work?
Upvotes: 0
Views: 5854
Reputation: 2647
I menaged to make it work at grid prerender instead of itemdatabound.
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
foreach (GridDataItem it in RadGrid1.EditItems)
{
TextBox sv = (TextBox)it["POZ_Stawka_VAT"].Controls[0];
if (sv.Text=="-1")
sv.Text = "zw";
}
}
protected void RadGrid1_DataBinding(object sender, EventArgs e)
{
for (int i = 0; i < RadGrid1.PageSize; i++)
{
RadGrid1.EditIndexes.Add(i);
}
}
Upvotes: 3
Reputation: 50728
it's not a good practice to set the editindexes in prerender and rebinding. When you do that, you wipe out all the changes you made at any other point because lifecycle is: init, load, control events, prerender. If you always work in edit mode for all rows, it would be best to listen to RadGrid.DataBinding, set the edit indexes, and then when its bound, the UI will update without any additional work or additional bindings.
protected void grid_databinding(..) {
for (int i = 0; i < RadGPozycje.PageSize; i++)
{
RadGPozycje.EditIndexes.Add(i);
}
}
Upvotes: 1