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

Radiobutton in editform of radgrid

8 Answers 295 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PV
Top achievements
Rank 1
PV asked on 25 Oct 2010, 01:23 PM
Hello Team,

I need to give 3 radio buttons in edit form (type 1, type2 , type3) based on which the rest of edit form is desiged(shown/hidden).
How do i bind these radio buttons as the values that comes from database is (id for type, 1 , 2 , 3) I need to check appropriate radiobutton based on id.
Should I handle this in databound without binding this it design time?

Any pointers .

8 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 27 Oct 2010, 01:13 PM
Hi PV,

You can either use ItemDataBound and modify the edit form at runtime, depending on some datasource values, or use something like this:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<script runat="server">
 
protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable dt = new DataTable();
    DataRow dr;
    int colsNum = 4;
    int rowsNum = 200;
    string colName = "Column";
 
    for (int j = 1; j <= colsNum; j++)
    {
        dt.Columns.Add(String.Format("{0}{1}", colName, j));
    }
 
    for (int i = 1; i <= rowsNum; i++)
    {
        dr = dt.NewRow();
 
        for (int k = 1; k <= colsNum; k++)
        {
            dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1} Row{2}", colName, k, i);
        }
        dt.Rows.Add(dr);
    }
 
    (sender as RadGrid).DataSource = dt;
}
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridPagerItem)
    {
        RadComboBox c = e.Item.FindControl("PageSizeComboBox") as RadComboBox;
        c.OnClientSelectedIndexChanged = "handlerName";
    }
}
     
</script>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadGrid
    ID="RadGrid1"
    runat="server"
    AutoGenerateEditColumn="true"
    AllowPaging="true"
    DataSourceID="DS1">
    <MasterTableView EditMode="EditForms">
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                <asp:RadioButton ID="RadioButton1" runat="server" GroupName="MyFlag" Checked='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="1"?true:false) %>' Text="1" />
                <asp:RadioButton ID="RadioButton2" runat="server" GroupName="MyFlag" Checked='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="2"?true:false) %>' Text="2" />
                <asp:RadioButton ID="RadioButton3" runat="server" GroupName="MyFlag" Checked='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="3"?true:false) %>' Text="3" />
 
                <asp:Panel ID="P1" runat="server" Visible='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="1"?true:false) %>'>
                    Panel 1
                </asp:Panel>
 
                <asp:Panel ID="P2" runat="server" Visible='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="2"?true:false) %>'>
                    Panel 2
                </asp:Panel>
 
                <asp:Panel ID="P3" runat="server" Visible='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="3"?true:false) %>'>
                    Panel 3
                </asp:Panel>
 
            </FormTemplate>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>
 
<asp:XmlDataSource ID="DS1" runat="server">
<Data>
    <nodes>
        <node ID="1" MyFlag="1" Text="Text 1" />
        <node ID="2" MyFlag="2" Text="Text 2" />
        <node ID="3" MyFlag="3" Text="Text 3" />
    </nodes>
</Data>
</asp:XmlDataSource>
 
</form>
</body>
</html>


Sincerely yours,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
PV
Top achievements
Rank 1
answered on 29 Oct 2010, 08:53 AM

Hi Dimo,

Thank you so much for reply.

 

Itemdatabound was quite messy, I exactly was looking for something you have sent.

 

How do I show a search popup  on edit form, how do I handle its click event?
Will that be normal buttonclick event to be handled or something else as its in editform?

 

 

Any pointers would be great.

0
Dimo
Telerik team
answered on 29 Oct 2010, 09:51 AM
Hi PV,

>> How do I show a search popup  on edit form, how do I handle its click event? Will that be normal buttonclick event to be handled or something else as its in editform?

When using a FormTemplate its content should be implemented pretty much the same as if it were outside RadGrid. If you want to ajaxify a control inside the FormTemplate, you should do this in RadGrid.PreRender by adding an AJAX setting programmatically:

http://www.telerik.com/help/aspnet-ajax/ajxaddajaxsettingsprogrammatically.html

If your case seems to be different, then prepare a simple demo, similar to the one I sent, in order to show us what exactly you are trying to do.

Regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
PV
Top achievements
Rank 1
answered on 29 Oct 2010, 10:15 AM

Hi Dimo,

Can I use RadAjaxManager as I am already using scriptmanager in masterpage where this usercontrol (which has Radgrid) is place?
And updatepanel on the usercontrol..should I replace it with Radajaxmanager?

I guess I will not be able use, and use either of the one.

Please suggest

0
PV
Top achievements
Rank 1
answered on 29 Oct 2010, 10:24 AM
Hello Dimo,

I tried using the way you suggested for radiobutton problem.

When in insertmode, I need to have first radiobutton chequed, and first panel visible which I handled in itemdatabound event.

But the the respective panel should be visible based on selection of radio button.
Should the checkchanged event be handled or is there an alternate way?


0
Dimo
Telerik team
answered on 29 Oct 2010, 10:48 AM
Hi PV,

>> Can I use RadAjaxManager as I am already using scriptmanager in masterpage where this usercontrol (which has Radgrid) is place?

RadAjaxManager is not related to the script manager, except that RadAjaxManager must appear or be added to the page after the script manager.

>> And updatepanel on the usercontrol..should I replace it with Radajaxmanager?

Yes, you should replace it.

>> Should the checkchanged event be handled or is there an alternate way?

Yes, you need to ajaxify the controls in the RadGrid edit form programmatically in RadGrid.PrePrender. Use RadGrid.MasterTableView.GetItems() to retrieve the edit form item and then FindControl() to retrieve the controls inside.

An alternative way is to use RadTabStrip and RadMultiPage inside the form template.

http://demos.telerik.com/aspnet-ajax/tabstrip/examples/functionality/multipage/defaultcs.aspx

However, this may not be possible, if you actually need RadioButtonList for its value.

Best wishes,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
PV
Top achievements
Rank 1
answered on 29 Oct 2010, 10:57 AM
>> Should the checkchanged event be handled or is there an alternate way?

Yes, you need to ajaxify the controls in the RadGrid edit form programmatically in RadGrid.PrePrender. Use RadGrid.MasterTableView.GetItems() to retrieve the edit form item and then FindControl() to retrieve the controls inside.

------------

How do I get reference to editform in the radiobuttoncheckchanged event?
As I need to find panel control to show or hide it
0
Dimo
Telerik team
answered on 03 Nov 2010, 02:20 PM
Hi PV,

You can use the radio button's Parent property. Here are two examples.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
  
<script runat="server">
  
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    RadGrid grid = sender as RadGrid;
    foreach (GridItem item in grid.MasterTableView.GetItems(GridItemType.EditFormItem))
    {
        if (item.IsInEditMode)
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(item.FindControl("EditFormWrapper"), item.FindControl("EditFormWrapper"));
    }
}
 
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
    RadioButton rb = sender as RadioButton;
    rb.Parent.FindControl("P1").Visible = rb.Checked;
    rb.Parent.FindControl("P2").Visible = !rb.Checked;
    rb.Parent.FindControl("P3").Visible = !rb.Checked;
}
 
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
    RadioButton rb = sender as RadioButton;
    rb.Parent.FindControl("P1").Visible = !rb.Checked;
    rb.Parent.FindControl("P2").Visible = rb.Checked;
    rb.Parent.FindControl("P3").Visible = !rb.Checked;
}
 
protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
    RadioButton rb = sender as RadioButton;
    rb.Parent.FindControl("P1").Visible = !rb.Checked;
    rb.Parent.FindControl("P2").Visible = !rb.Checked;
    rb.Parent.FindControl("P3").Visible = rb.Checked;
}
 
</script>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Vista" />
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
</telerik:RadAjaxManager>
 
<telerik:RadGrid
    ID="RadGrid1"
    runat="server"
    Skin="Vista"
    Width="800px"
    AutoGenerateEditColumn="true"
    DataSourceID="DS1" OnPreRender="RadGrid1_PreRender">
    <MasterTableView EditMode="EditForms">
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                <asp:Panel ID="EditFormWrapper" runat="server">
                    <asp:RadioButton ID="RadioButton1" runat="server" GroupName="MyFlag" Checked='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="1"?true:false) %>' Text="1" AutoPostBack="true" OnCheckedChanged="RadioButton1_CheckedChanged" />
                    <asp:RadioButton ID="RadioButton2" runat="server" GroupName="MyFlag" Checked='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="2"?true:false) %>' Text="2" AutoPostBack="true" OnCheckedChanged="RadioButton2_CheckedChanged" />
                    <asp:RadioButton ID="RadioButton3" runat="server" GroupName="MyFlag" Checked='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="3"?true:false) %>' Text="3" AutoPostBack="true" OnCheckedChanged="RadioButton3_CheckedChanged" />
  
                    <asp:Panel ID="P1" runat="server" Visible='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="1"?true:false) %>'>
                        Panel 1
                    </asp:Panel>
  
                    <asp:Panel ID="P2" runat="server" Visible='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="2"?true:false) %>'>
                        Panel 2
                    </asp:Panel>
  
                    <asp:Panel ID="P3" runat="server" Visible='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="3"?true:false) %>'>
                        Panel 3
                    </asp:Panel>
                </asp:Panel>
            </FormTemplate>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>
  
<asp:XmlDataSource ID="DS1" runat="server">
<Data>
    <nodes>
        <node ID="1" MyFlag="1" Text="Text 1" />
        <node ID="2" MyFlag="2" Text="Text 2" />
        <node ID="3" MyFlag="3" Text="Text 3" />
    </nodes>
</Data>
</asp:XmlDataSource>
  
</form>
</body>
</html>




<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
  
<script runat="server">
  
protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable dt = new DataTable();
    DataRow dr;
    int colsNum = 4;
    int rowsNum = 200;
    string colName = "Column";
  
    for (int j = 1; j <= colsNum; j++)
    {
        dt.Columns.Add(String.Format("{0}{1}", colName, j));
    }
  
    for (int i = 1; i <= rowsNum; i++)
    {
        dr = dt.NewRow();
  
        for (int k = 1; k <= colsNum; k++)
        {
            dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1} Row{2}", colName, k, i);
        }
        dt.Rows.Add(dr);
    }
  
    (sender as RadGrid).DataSource = dt;
}
  
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridPagerItem)
    {
        RadComboBox c = e.Item.FindControl("PageSizeComboBox") as RadComboBox;
        c.OnClientSelectedIndexChanged = "handlerName";
    }
}
 
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    RadGrid grid = sender as RadGrid;
    foreach (GridItem item in grid.MasterTableView.GetItems(GridItemType.EditFormItem))
    {
        if (item.IsInEditMode)
        {
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(item.FindControl("EditFormWrapper"), item.FindControl("EditFormWrapper"));
            item.FindControl("P1").Visible = (item.FindControl("RadioButton1") as RadioButton).Checked;
            item.FindControl("P2").Visible = (item.FindControl("RadioButton2") as RadioButton).Checked;
            item.FindControl("P3").Visible = (item.FindControl("RadioButton3") as RadioButton).Checked;
        }
    }
}
 
</script>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Transparency="50" BackColor="Yellow" />
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
</telerik:RadAjaxManager>
 
<telerik:RadGrid
    ID="RadGrid1"
    runat="server"
    AutoGenerateEditColumn="true"
    AllowPaging="true"
    DataSourceID="DS1" OnPreRender="RadGrid1_PreRender">
    <MasterTableView EditMode="EditForms">
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                <asp:Panel ID="EditFormWrapper" runat="server">
                    <asp:RadioButton ID="RadioButton1" runat="server" GroupName="MyFlag" Checked='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="1"?true:false) %>' Text="1" AutoPostBack="true" />
                    <asp:RadioButton ID="RadioButton2" runat="server" GroupName="MyFlag" Checked='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="2"?true:false) %>' Text="2" AutoPostBack="true" />
                    <asp:RadioButton ID="RadioButton3" runat="server" GroupName="MyFlag" Checked='<%# (DataBinder.Eval(Container.DataItem,"MyFlag").ToString()=="3"?true:false) %>' Text="3" AutoPostBack="true" />
  
                    <asp:Panel ID="P1" runat="server">
                        Panel 1
                    </asp:Panel>
  
                    <asp:Panel ID="P2" runat="server">
                        Panel 2
                    </asp:Panel>
  
                    <asp:Panel ID="P3" runat="server">
                        Panel 3
                    </asp:Panel>
                </asp:Panel>
            </FormTemplate>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>
  
<asp:XmlDataSource ID="DS1" runat="server">
<Data>
    <nodes>
        <node ID="1" MyFlag="1" Text="Text 1" />
        <node ID="2" MyFlag="2" Text="Text 2" />
        <node ID="3" MyFlag="3" Text="Text 3" />
    </nodes>
</Data>
</asp:XmlDataSource>
  
</form>
</body>
</html>



Best wishes,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
PV
Top achievements
Rank 1
Answers by
Dimo
Telerik team
PV
Top achievements
Rank 1
Share this question
or