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

Combobox in Rad Grid in Editmode and Insert Mode

5 Answers 212 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 22 Oct 2013, 05:55 AM
Hi,
i am having grid in which i am doing crud operations but for one column i want combobox rather than textbox(EntityType) in both the mode.
My code is
<%@ Page Title="" Language="C#" MasterPageFile="~/MPLayout.master" AutoEventWireup="true"
    CodeFile="EntityDetailsGrid.aspx.cs" Inherits="EntityDetailsGrid" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<%--Style Applied For The Textbox Inside Automatic Insert And Edit Mode--%>
    <style type="text/css">
        .riEditFormTextBox
        {
            margin-top: 4px;
            width: 340px;
            height:21px;
        }
    </style>
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="15" AllowSorting="true"
        ShowGroupPanel="true" OnPreRender="RadGrid1_PreRender" HeaderStyle-Font-Bold="true"
        Skin="Black" onitemcreated="RadGrid1_ItemCreated"
        onneeddatasource="RadGrid1_NeedDataSource1"
        oninsertcommand="RadGrid1_InsertCommand"
        onitemcommand="RadGrid1_ItemCommand"
        ondeletecommand="RadGrid1_DeleteCommand"
        onupdatecommand="RadGrid1_UpdateCommand" >
        <PagerStyle AlwaysVisible="true" Font-Bold="true" Mode="NextPrevNumericAndAdvanced" />
        <ClientSettings AllowDragToGroup="true" AllowColumnsReorder="true" Resizing-AllowResizeToFit="true">
         <Selecting AllowRowSelect="True" UseClientSelectColumnOnly="True"></Selecting>
        </ClientSettings>
        <ExportSettings ExportOnlyData="true" OpenInNewWindow="true" IgnorePaging="true"
            FileName="Entity Details">
            <Pdf AllowAdd="true" AllowCopy="true" AllowModify="true" AllowPrinting="true" BorderColor="Black"
                BorderStyle="Medium" BorderType="AllBorders" PageBottomMargin="20px" PageFooter-LeftCell-TextAlign="Center"
                PageFooterMargin="20px" PageHeader-LeftCell-TextAlign="Center" PageHeaderMargin="20px"
                PageLeftMargin="35px" PageRightMargin="35px" PageTitle="List Of Entities and Details"
                PageTopMargin="35px" PaperSize="A4" UserPassword="ss">
            </Pdf>
        </ExportSettings>
        <MasterTableView CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="true" EditMode="EditForms" DataKeyNames="EntityId"
            CommandItemSettings-ShowRefreshButton="false">
            <CommandItemSettings ShowExportToCsvButton="true" ShowExportToExcelButton="true"
                ShowExportToPdfButton="true" ShowExportToWordButton="true" />
                <EditFormSettings FormMainTableStyle-HorizontalAlign="Center" EditColumn-ButtonType="PushButton"
                                        FormTableStyle-Width="100%" FormTableButtonRowStyle-HorizontalAlign="Center"
                                        FormTableStyle-CellPadding="3" FormMainTableStyle-Font-Bold="true" FormMainTableStyle-ForeColor="Purple"
                                        FormStyle-CssClass="" FormTableStyle-CellSpacing="5" InsertCaption="Add New Record"
                                        FormCaptionStyle-Font-Bold="true" FormCaptionStyle-Font-Underline="true" FormCaptionStyle-ForeColor="Black"
                                        FormCaptionStyle-Font-Size="Large" FormCaptionStyle-HorizontalAlign="Center"
                                        FormCaptionStyle-Width="100%">
                                        <FormStyle Width="100%" BackColor="LightCyan"></FormStyle>
                                         
                                    </EditFormSettings>
                                     
                <Columns>
              
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditColumn"></telerik:GridEditCommandColumn>
                    <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" UniqueName="DeleteColumn" ConfirmText="Are you sure to Delete this Record?"  ConfirmDialogType="RadWindow" ConfirmTitle="<b>Manifest-BI :: Delete</b>"></telerik:GridButtonColumn>
                </Columns>
        </MasterTableView>
         
    </telerik:RadGrid>
</asp:Content>
and
How to Access the value from combobox on update and insert button click.

Thanks

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Oct 2013, 06:49 AM
Hi Swapnil,

Please try the following code snippet to have a radcombobox in edit and insert mode .

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" . . . .>
    <PagerStyle AlwaysVisible="true" Font-Bold="true" Mode="NextPrevNumericAndAdvanced" />
    <ClientSettings. . >
        . . . .
    </ClientSettings>
    <MasterTableView CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="true"
        EditMode="EditForms" DataKeyNames="OrderID" CommandItemSettings-ShowRefreshButton="false">
        <CommandItemSettings . . . />
        <EditFormSettings . . . .>
          . . .
        </EditFormSettings>
        <Columns>
          . . . . . .
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
    {
        if (col.DataType == typeof(string))
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode )
            {
                if (col.UniqueName == "ShipCountry")
                {
                    GridEditableItem item = (GridEditableItem)e.Item;
                    RadComboBox checks = (RadComboBox)item.FindControl("RadComboBox1");
                    checks.SelectedValue = DataBinder.Eval(item.DataItem, "ShipCountry").ToString();
                    checks.DataSourceID = "SqlDataSource1";
                    checks.DataTextField = "ShipCountry";
                    checks.DataValueField = "ShipCountry";
                }
            }
        }
    }
}
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
    {
        if (col.DataType == typeof(string))
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode )
            {
                if (col.UniqueName == "ShipCountry")
                {
                    GridEditableItem item = (GridEditableItem)e.Item;
                    TextBox txt = (TextBox)item[col.UniqueName].Controls[0];
                    txt.Visible = false;
                    RadComboBox checks = new RadComboBox();
                    checks.DataSourceID = "SqlDataSource1";
                    checks.DataTextField = "ShipCountry";
                    checks.DataValueField = "ShipCountry";
                    checks.ID = "RadComboBox1";                       
                    item[col.UniqueName].Controls.Add(checks);
                }
            }
        }
    }
}
protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.Item is GridEditableItem)
    {
        GridEditableItem update = (GridEditableItem)e.Item;
        string OrderID = update.GetDataKeyValue("OrderID").ToString();
        RadComboBox combo = (RadComboBox)update.FindControl("RadComboBox1");
        string val=combo.SelectedValue;
    }
}
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
    if (e.Item is GridEditableItem)
    {
        GridEditableItem insert = (GridEditableItem)e.Item;
        string id = (insert["OrderID"].Controls[0] as RadNumericTextBox).Text; 
        RadComboBox combo = (RadComboBox)insert.FindControl("RadComboBox1");
        string val = combo.SelectedValue;
    }
}

Thanks,
Shinu
0
Swapnil
Top achievements
Rank 1
answered on 23 Oct 2013, 11:04 AM
Hi Shinu ,
Thanks , is their any simple way to show success message after insert and update ,
i am using this for delete

<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ConfirmText="Are you sure to Delete this Record?"  ConfirmDialogType="RadWindow" ConfirmTitle=""
                                            ButtonType="ImageButton" />
Thanks
0
Shinu
Top achievements
Rank 2
answered on 24 Oct 2013, 05:06 AM
Hi Swapnil,

You can either use a Label and display text in it after the successful updation.

ASPX:
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

C#:
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
{
   try
    {
    GridDataItem edit = (GridDataItem)e.Item;
     string ID = edit.GetDataKeyValue("ID").ToString();
     //Code to delete
     Label1.Text = "Product with ID " + ID + " is Deleted!";
    }
 
    catch (Exception ex)
    {
    Label1.Text = "Product cannot be Deleted!";
    }       
}

Thanks,
Shinu

0
Swapnil
Top achievements
Rank 1
answered on 25 Oct 2013, 04:24 AM
i dont want to show error/success like his,
i want to show radpopup like i showed for delete ask confiration
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ConfirmText="Are you sure to Delete this Record?"  ConfirmDialogType="RadWindow" ConfirmTitle=""
                                            ButtonType="ImageButton" />
Thanks
0
Accepted
Shinu
Top achievements
Rank 2
answered on 25 Oct 2013, 05:29 AM
Hi Swapnil,

You can use a RadAlert to show a popup Confirmation.Please try the following code snippet.

ASPX:
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>

C#:
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
{
 try
  {
  //Code to Delete    
   RadWindowManager1.RadAlert("Successfully Deleted!", 300, 200,"Delete",null);
  }
 catch (Exception ex)
  {
   RadWindowManager1.RadAlert("Delete not Successfull!", 300, 200,"Delete",null);
  }       
}

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