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

Having problem With GridDropDownColumn

2 Answers 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ashish
Top achievements
Rank 1
Ashish asked on 12 Jul 2013, 03:57 PM
When I Edit the selected record.Dropdown selected index be 0 while i want it as well as i retreive from Data.
My Code is like-

 

<telerik:RadGrid ID="grdAudotex" OnItemDataBound="grdAudotex_ItemDataBound" MasterTableView-NoMasterRecordsText="no records found"

 

OnDeleteCommand="grdAudotex_DeleteCommand" OnUpdateCommand="grdAudotex_UpdateCommand" AllowPaging="true" PageSize="4" OnInsertCommand="grdAudotex_InsertCommand" OnPreRender="grdAudotex_PreRender" OnNeedDataSource="grdAudotex_NeedDataSource" runat="server">

 

<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>

 

<MasterTableView Width="100%" AutoGenerateColumns="false" EditMode="EditForms" CommandItemDisplay="Top" DataKeyNames="Id" InsertItemPageIndexAction="ShowItemOnCurrentPage">

 

<Columns>

 

<telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-HorizontalAlign="left" />

<%

 

--<telerik:GridBoundColumn UniqueName="Id" DataField="Id" HeaderText="JobID" Visible="false">

</telerik:GridBoundColumn>--

 

 

%>

<%

 

-- <telerik:GridBoundColumn UniqueName="JobTask" DataField="JobTask" HeaderText="Job Task">

</telerik:GridBoundColumn>--

 

 

%>

 

<telerik:GridDropDownColumn UniqueName="ddlstJobTask" EditFormHeaderTextFormat="Job Task" EditFormColumnIndex="0" ListTextField="JobTask" ListValueField="JobTask" ListDataMember="LABOURTYPE" DataField="JobTask" DropDownControlType="RadComboBox" HeaderText="Job Task"></telerik:GridDropDownColumn>

<%

 

--<telerik:GridBoundColumn UniqueName="Description" DataField="Description" HeaderText="Internal Job Task">

</telerik:GridBoundColumn>--

 

 

%>

 

<telerik:GridDropDownColumn UniqueName="ddlstDescription" EditFormHeaderTextFormat="Internal Job Task" EditFormColumnIndex="0" ListTextField="InternalJobTask" ListValueField="InternalJobTask" DropDownControlType="RadComboBox" ListDataMember="InternalJobTask" DataField="InternalJobTask" HeaderText="Internal Job Task"></telerik:GridDropDownColumn>

<%

 

--<telerik:GridBoundColumn UniqueName="WorkProvider" DataField="Name" HeaderText="WorkProvider">

</telerik:GridBoundColumn>--

 

 

%>

 

<telerik:GridDropDownColumn UniqueName="ddlstWorkProvider" EditFormHeaderTextFormat="WorkProvider" EditFormColumnIndex="0" ListTextField="Name" ListValueField="Name" ListDataMember="Name" DropDownControlType="RadComboBox" DataField="Name" HeaderText="WorkProvider"></telerik:GridDropDownColumn>

 

<telerik:GridBoundColumn HeaderText="JobTaskContainingWord" EditFormHeaderTextFormat="JobTaskContainingWord" EditFormColumnIndex="1" DataField="JobTaskContainingWord" UniqueName="txtJobTaskContainingWord">

 

<ColumnValidationSettings EnableRequiredFieldValidation="true">

 

<RequiredFieldValidator ForeColor="Red" Text="*This field is required">

 

</RequiredFieldValidator>

 

</ColumnValidationSettings>

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn HeaderText="Percentage" EditFormHeaderTextFormat="Percentage" EditFormColumnIndex="1" UniqueName="txtPercentage" DataField="Percentage">

 

</telerik:GridBoundColumn>

 

<telerik:GridButtonColumn ConfirmText="Delete this setting?" ConfirmDialogType="RadWindow"

 

ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"

 

UniqueName="DeleteColumn">

 

<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>

 

</telerik:GridButtonColumn>

 

</Columns>

 

<EditFormSettings ColumnNumber="2">

 

<FormTableItemStyle Wrap="false"></FormTableItemStyle>

 

<FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>

 

<FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="2" Width="100%"></FormMainTableStyle>

 

<FormTableStyle CellSpacing="0" CellPadding="2" Height="60px"></FormTableStyle>

 

<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>

 

<EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"

 

UniqueName="EditCommandColumn1" CancelText="Cancel edit">

 

</EditColumn>

 

<FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>

 

</EditFormSettings>

 

</MasterTableView>

 

<ClientSettings>

 

<ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>

 

</ClientSettings>

 

</telerik:RadGrid>


and ItemDataBound is like this-

 

 

 

 

 

 

protected void grdAudotex_ItemDataBound(object sender, GridItemEventArgs e)

{

 

 

 

 

 

if (e.Item is GridEditableItem && e.Item.IsInEditMode)

{

 

 

 

 

 

GridEditableItem edititem = (GridEditableItem)e.Item;

 

 

 

 

 

GridEditManager editMan = edititem.EditManager;

 

 

 

 

 

GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ddlstJobTask"));

 

 

 

 

 

RadComboBox rComboBox = editor.ComboBoxControl;

 

 

 

 

 

var LabourType = (from obj in dc.LABOURTYPEs

 

 

 

 

 

select new

{

obj.Id,

obj.LabourCode,

obj.LabourDescription

}).ToList();

rComboBox.DataSource = LabourType;

rComboBox.DataValueField =

 

 

 

 

 

"Id";

rComboBox.DataTextField =

 

 

 

 

 

"LabourDescription";

rComboBox.DataBind();

 

 

 

 

 

GridDropDownListColumnEditor EditorInternalJob = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ddlstDescription"));

 

 

 

 

 

RadComboBox cmbInternalJob = EditorInternalJob.ComboBoxControl;

 

 

 

 

 

var InterJobTask = (from objJob in dc.ESTIMATEJOBTYPEs

 

 

 

 

 

select new

{

objJob.JobTypeId,

objJob.JobCode,

objJob.Description

}).ToList();

cmbInternalJob.DataSource = InterJobTask;

cmbInternalJob.DataValueField =

 

 

 

 

 

"JobTypeId";

cmbInternalJob.DataTextField =

 

 

 

 

 

"Description";

cmbInternalJob.DataBind();

 

 

 

 

 

GridDropDownListColumnEditor EditorWorkProvider = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ddlstWorkProvider"));

 

 

 

 

 

RadComboBox cmbWorkprovider = EditorWorkProvider.ComboBoxControl;

 

 

 

 

 

var WorkProvider = (from objWork in dc.WORKPROVIDERs

 

 

 

 

 

select new

{

objWork.WorkProviderId,

objWork.Name,

}).ToList();

cmbWorkprovider.DataSource = WorkProvider;

cmbWorkprovider.DataValueField =

 

 

 

 

 

"WorkProviderId";

cmbWorkprovider.DataTextField =

 

 

 

 

 

"Name";

cmbWorkprovider.DataBind();

 

 

 

 

 

GridTextBoxColumnEditor EditorPercentage = (GridTextBoxColumnEditor)(editMan.GetColumnEditor("txtPercentage"));

 

 

 

 

 

TextBox txtPercentage1 = EditorPercentage.TextBoxControl;

 

 

 

 

 

GridTextBoxColumnEditor EditorContaingWord = (GridTextBoxColumnEditor)(editMan.GetColumnEditor("txtJobTaskContainingWord"));

 

 

 

 

 

TextBox txtcont = EditorContaingWord.TextBoxControl;

 

}

}

 

protected void grdAudotex_ItemDataBound(object sender, GridItemEventArgs e)

{

 

if (e.Item is GridEditableItem && e.Item.IsInEditMode)

{

 

GridEditableItem edititem = (GridEditableItem)e.Item;

 

GridEditManager editMan = edititem.EditManager;

 

GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ddlstJobTask"));

 

RadComboBox rComboBox = editor.ComboBoxControl;

 

var LabourType = (from obj in dc.LABOURTYPEs

 

select new

{

obj.Id,

obj.LabourCode,

obj.LabourDescription

}).ToList();

rComboBox.DataSource = LabourType;

rComboBox.DataValueField =

 

"Id";

rComboBox.DataTextField =

 

"LabourDescription";

rComboBox.DataBind();

 

GridDropDownListColumnEditor EditorInternalJob = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ddlstDescription"));

 

RadComboBox cmbInternalJob = EditorInternalJob.ComboBoxControl;

 

var InterJobTask = (from objJob in dc.ESTIMATEJOBTYPEs

 

select new

{

objJob.JobTypeId,

objJob.JobCode,

objJob.Description

}).ToList();

cmbInternalJob.DataSource = InterJobTask;

cmbInternalJob.DataValueField =

 

"JobTypeId";

cmbInternalJob.DataTextField =

 

"Description";

cmbInternalJob.DataBind();

 

GridDropDownListColumnEditor EditorWorkProvider = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ddlstWorkProvider"));

 

RadComboBox cmbWorkprovider = EditorWorkProvider.ComboBoxControl;

 

var WorkProvider = (from objWork in dc.WORKPROVIDERs

 

select new

{

objWork.WorkProviderId,

objWork.Name,

}).ToList();

cmbWorkprovider.DataSource = WorkProvider;

cmbWorkprovider.DataValueField =

 

"WorkProviderId";

cmbWorkprovider.DataTextField =

 

"Name";

cmbWorkprovider.DataBind();

 

GridTextBoxColumnEditor EditorPercentage = (GridTextBoxColumnEditor)(editMan.GetColumnEditor("txtPercentage"));

 

TextBox txtPercentage1 = EditorPercentage.TextBoxControl;

 

GridTextBoxColumnEditor EditorContaingWord = (GridTextBoxColumnEditor)(editMan.GetColumnEditor("txtJobTaskContainingWord"));

 

TextBox txtcont = EditorContaingWord.TextBoxControl;

 

}

}


Hi please suggest me .

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 15 Jul 2013, 11:06 AM
Hi Ashish,

I'm not sure about your requirement.I guess you want to access the GridDropDownColumn in edit mode to retrieve the selected value.Please try the below code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"   AllowPaging="true"  AutoGenerateEditColumn="true"   onitemcreated="RadGrid1_ItemCreated">
    <MasterTableView DataKeyNames="OrderID">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
            <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" />
            <telerik:GridDropDownColumn DataField="ShipCity" EmptyListItemText="-- Select City --"
                DataSourceID="SqlDataSource2" EnableEmptyListItem="True" HeaderText="ShipCity"
                ListTextField="ShipCity" ListValueField="ShipCity" UniqueName="ShipCity" DropDownControlType="RadComboBox">
            </telerik:GridDropDownColumn>
        </Columns>
    </MasterTableView
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        RadComboBox combo = (RadComboBox)editedItem["ShipCity"].Controls[0];
        combo.AutoPostBack = true;
        combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);
    }
}
 
void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox com = (RadComboBox)sender;
    string selectedvalue = com.SelectedValue;//Accessing the selected value of DropDown list
}

Thanks,
Princy
0
Ashish
Top achievements
Rank 1
answered on 16 Jul 2013, 07:43 AM
Hi, 
I have done this 
Thanks for support.
Tags
Grid
Asked by
Ashish
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Ashish
Top achievements
Rank 1
Share this question
or