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

RadGrid EditItemStyle not working

7 Answers 215 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jagat
Top achievements
Rank 1
Jagat asked on 14 Mar 2012, 09:20 PM
 
Hello,

  I am working on Radgrid in one of my web pages. I have 3 questions on this.

1)  I want to change the backcolor of the edited row and for that i have given the edititemstyle and still don't see the color.Am i doing something wrong here? Here is the code.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"
                              OnDeleteCommand="RadGrid1_DeleteCommand" ShowStatusBar="True"
                               ShowFooter="True" Skin="Office2010Silver" Width="100%"
                              OnItemDataBound="RadGrid1_ItemDataBound" OnEditCommand="RadGrid1_EditCommand"
                              OnNeedDataSource="RadGrid1_NeedDataSource" 
                              OnUpdateCommand="RadGrid1_UpdateCommand" GridLines="None"
                              oninsertcommand="RadGrid1_InsertCommand" CellSpacing="0" Font-Bold="True"
                              ForeColor="Black">
                               <EditItemStyle  BackColor="DarkOrange"   BorderColor="#C00000" HorizontalAlign="Center" VerticalAlign="Middle" />
                              <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                             
                              </HeaderContextMenu>                              
                               <ItemStyle Font-Bold="True" />                                 
                              <MasterTableView AllowAutomaticDeletes="True" CommandItemDisplay="Top" DataKeyNames="ClientID" EditMode="EditForms" >


2) Suppose I have 4 columns in the grid and when i edit a row, i would like to see the half of the columns on the left and the other half on the right. Something like this..

Column1       Column3
Column2       Column4

 I don't want to have all the columns straight. It will take more height.


3) I have a template column in the grid and it should bind the gender . It may be M or F or null. What i have works only  if the grid is NOT in edit mode. Is there a property which will bind the gender and should not throw a error if the value is null?
<telerik:GridTemplateColumn HeaderText="Gender" UniqueName="MemGender">
                                          <EditItemTemplate>
                                              <ASP:RadioButtonList ID="rbtnMemGender" runat="server" CssClass="radiobutton" 
                                              RepeatDirection="Horizontal"  >
                                                  <ASP:ListItem Text="M" Value="M" />
                                                  <ASP:ListItem Text="F" Value="F" />                                                 
                                              </ASP:RadioButtonList>
                                          </EditItemTemplate>
                                          <ItemTemplate>
                                              <ASP:Label ID="lblMemGender" runat="server" Text='<%# Bind("Gender") %>' ToolTip="Gender">
                                              </ASP:Label>
                                          </ItemTemplate>
                                      </telerik:GridTemplateColumn>

 



Appreciate the help.

7 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 14 Mar 2012, 09:50 PM
can't help you with the EditItemStyle but to make a custom format - use either the FormTemplate or a UserControl

- thanks Shinu
0
Jagat
Top achievements
Rank 1
answered on 14 Mar 2012, 11:08 PM
Could you explain me how do i get this working by using  edititemtemplate?

Thanks
0
Accepted
Shinu
Top achievements
Rank 2
answered on 15 Mar 2012, 09:19 AM
Hi Jagat,

For the first and second requirement you can customize the edit form using FormTemplate and can give BackColor using FormStyle.
Please take a look into the following design:
aspx:
<EditFormSettings EditFormType="Template" FormStyle-BackColor="DarkOrange" FormStyle-BorderColor="#C00000">                   
 <FormTemplate>
   <table>
    <tr>
     <td>
       <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("EmployeeID") %>'></asp:TextBox>
     </td>
     <td>
       <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
     </td>
    </tr>
    <tr>
     <td>
       <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
     </td>
     <td>
      <asp:RadioButtonList ID="rbtnMemGender" runat="server" CssClass="radiobutton" RepeatDirection="Horizontal" >
          <asp:ListItem Text="M" Value="M" />
          <asp:ListItem Text="F" Value="F" />                                                
       </asp:RadioButtonList>
     </td>
    </tr>
   </table>
 </FormTemplate>
</EditFormSettings>

3.Try the following code for binding the value 'gender' in edit form.
aspx:
<telerik:GridTemplateColumn UniqueName="gender" HeaderText="gender">
  <ItemTemplate>
     <asp:Label ID="lblMemGender" runat="server" Text='<%# Bind("Gender") %>' ToolTip="Gender"></asp:Label>
  </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem editItem = (GridEditFormItem)e.Item;
        GridDataItem dataItem = (GridDataItem)editItem.ParentItem;
        Label rbList = (Label)dataItem.FindControl("lblMemGender");
        RadioButtonList rbList1 = (RadioButtonList)editItem.FindControl("rbtnMemGender");
        if (rbList.Text.Trim() == "M")
        {
 
            rbList1.SelectedIndex = 0;
        }
        else if (rbList.Text.Trim() == "F")
        {
 
            rbList1.SelectedIndex = 1;
        }
 
    }
}

Thanks,
-Shinu.
0
Jagat
Top achievements
Rank 1
answered on 15 Mar 2012, 03:49 PM
Shinu,

 First two problems solved. Thanks.
Is there any way to bind the radiobuttonlist from aspx side? I don't want to have any overhead in code behind, Since the page is already slow.

Thanks
0
Shinu
Top achievements
Rank 2
answered on 16 Mar 2012, 05:30 AM
Hello Jagat,

You can directly bind the selected value in RadioButtonList as shown below.
aspx:
<telerik:GridTemplateColumn HeaderText="Gender" UniqueName="MemGender">
   <EditItemTemplate>
     <asp:RadioButtonList ID="rbtnMemGender" SelectedValue='<%# Bind("Gender") %>' runat="server" CssClass="radiobutton" RepeatDirection="Horizontal">
        <asp:ListItem Text="M" Value="M" />
        <asp:ListItem Text="F" Value="F" />
        <asp:ListItem Value="" Text="" style="display: none" />
     </asp:RadioButtonList>
 </EditItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Shinu.
0
Jagat
Top achievements
Rank 1
answered on 17 Mar 2012, 08:53 PM
Shinu,

  I did that. It is working only if the Gender is not null. If the value is null, it is throwing error. I want to check the value first and then bind it only if it is not null. 
0
Accepted
Shinu
Top achievements
Rank 2
answered on 19 Mar 2012, 06:06 AM
Hello Jagat,

The above code is working as expected in my end. I guess you are not adding the third ListItem to RadioButtonList which will handle the null values for Gender field.
aspx:
<asp:ListItem Value="" Text="" style="display: none" />
Also please make sure that your DataBase table contain the value 'NULL'  if the the gender field is empty.

Thanks,
Shinu.
Tags
Grid
Asked by
Jagat
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Jagat
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or