This is a migrated thread and some comments may be shown as answers.

How to set the visual style of a griddataitem and set it to edit?

1 Answer 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ChrisWalker
Top achievements
Rank 1
ChrisWalker asked on 21 Feb 2008, 06:39 PM
Hello-
I need to evaluate a grid data item (row) to see if certain fields can be edited based on values in this particular row. I also need to change the style of certain cells in that row if it does becomes editable.
Initially I set the styles of the cells in the ItemDataBound handler if I determine that this row has fields to edit. for example:

dataitem(

"groupid").Style.Add("visibility", "hidden")

this worked just fine.

I then needed to set this row to be editable.  (I have the grid to edit inplace). In the ItemDataBound handler, after I set the styles like the one above, I set the row to be editable:

dataitem.edit = true

Initially I did not see the cells become editable (showing textboxes instead of  labels).
After reading in the documentation that I need to rebind the grid after I change the edit property, I placed a rebind() in the page's PreRenderComplete handler:  

Me

.PreRenderComplete

This now shows the editable columns in the row BUT all of the style changes that I did in the ItemDataBound handler are lost. If I take out the rebind() in the PreRenderComplete the style changes are made but the editable columns are not set.

Is there a way to both set the style of a row dynamically and set it to be editable?

1 Answer, 1 is accepted

Sort by
0
ChrisWalker
Top achievements
Rank 1
answered on 22 Feb 2008, 08:10 PM
I decided to make the editable columns griditemtemplates with both a label and textbox in the itemtemplate. In the itemdatabound handler, I determine if it should be editable or not and adjust the visibility/display styles of the controls in the template accordingly.

<telerik:GridTemplateColumn UniqueName="LastName" HeaderText="Last Name" HeaderStyle-Width="10%" >

<ItemTemplate>

<div>

<div style="float:left;width:20%">

<asp:RadioButton ID="rdoUseLastName" runat="server" />

</div>

<div style="float:left;width:70%">

<asp:Label ID="lblLastName" runat="server"></asp:Label>

<asp:TextBox ID="txtLastName" style="width:100%" runat="server"></asp:TextBox>

</div>

</div>

</ItemTemplate>

</telerik:GridTemplateColumn>


It seems to work the way I want and I do not have to do any client side manipulation.
Tags
Grid
Asked by
ChrisWalker
Top achievements
Rank 1
Answers by
ChrisWalker
Top achievements
Rank 1
Share this question
or