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

grid customization questions

4 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Henry
Top achievements
Rank 1
Henry asked on 02 Apr 2012, 03:42 AM
I am just started trying RadControl AJAX. I have questions for the Grid.

1)I am able to use the default add/edit form, now how can I customize the add/edit record form? For example, use dropboxlist? (which need to be populated from a list of value and then the current value is selected), use checkbox?(which should bind to current true/false value for bool type data).

2)how to align filter cell? I am expecting "FilterStyle" property, but not found.

Thanks.

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 02 Apr 2012, 05:13 AM
Hello Henry,

You can customize the edit form either using FormTemplate or EditItemTemplate as shown below.
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" AutoGenerateColumns="false" AllowFilteringByColumn="true" OnItemCreated="RadGrid1_ItemCreated">
 <MasterTableView >
  <EditFormSettings EditFormType="Template">
    <FormTemplate>
       <asp:DropDownList ID="ddl" runat="server"></asp:DropDownList>
    </FormTemplate>
 </EditFormSettings>
   <Columns>
     <telerik:GridTemplateColumn>
        <EditItemTemplate>
          <asp:CheckBox ID="CheckBox1" runat="server" />
        </EditItemTemplate>
     </telerik:GridTemplateColumn>
  </Columns>
 </MasterTableView>
</telerik:RadGrid>
Try the following code to align the filter cell in ItemCreated event.
C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridFilteringItem)
 {
   GridFilteringItem item = e.Item as GridFilteringItem;
   item["UniqueName"].HorizontalAlign = HorizontalAlign.Right;
 }
}
Also check the following demo which implements editing using FormTemplate.
Grid / Form Template Edit Form

Thanks,
Shinu.
0
Henry
Top achievements
Rank 1
answered on 02 Apr 2012, 05:47 AM
Shinu, thanks for quick response! Followup questions for the first one:

currently I am using code behind cs file to do coding, when update or insert, I am using UpdateValues method to get the values from popup window input and update the object, then save it to database. now with custom EditItemTemplate,
1) will I still able to to use that to get input values? Or do I need to find those controls(say "ddl" or "checkbox1") and get the values manually? 
2) in the example you point to, the dropdownlist is hardcoded, how can I dynamically populate it in the code behind?

0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Apr 2012, 06:31 AM
Hello Henry,

You can access the DropDownList and CheckBox in ItemDataBound event using FindControl method. Here is the sample code.
C#:
protected void grid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
 {
   GridEditFormItem item = (GridEditFormItem)e.Item;
   DropDownList ddl = (DropDownList)item.FindControl("ddl");
   CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
   ddl.DataTextField = "Id";
   ddl.DataValueField = "Id";
   ddl.DataSourceID = "SqlDataSource1";
 }
}

Thanks,
Shinu.
0
Henry
Top achievements
Rank 1
answered on 03 Apr 2012, 07:35 PM
Thank you!
Tags
Grid
Asked by
Henry
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Henry
Top achievements
Rank 1
Share this question
or