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

want to assign value to gridbound column on combobox selected changed event

7 Answers 239 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shankar mohan
Top achievements
Rank 1
shankar mohan asked on 03 Apr 2010, 08:34 AM
i ve griddropdowncolumn and gridbound columns on my radgrid
while selecting the value from dropdown i need to bind values on bound columns n also i want to make some bound columns read only true on the selected index changes event
<telerik:radgrid   ID="RadGrid1" runat="server" Height="300" Visible="true" BackColor="LightBlue" ShowFooter="true" PageSize="20" AllowPaging="True" AllowFilteringByColumn="True" AllowSorting="true" ShowStatusBar="true" GridLines="None" AutoGenerateColumns="False" Skin="Vista"   OnPreRender="RadGrid1_PreRender"  OnItemDataBound ="RadGrid1_ItemDataBound" OnItemCreated="RadGrid1_ItemCreated"  OnNeedDataSource="RadGrid1_NeedDataSource" OnColumnCreated="RadGrid1_ColumnCreated" >                                                                                                                              
                <MasterTableView      CommandItemDisplay="Top" AutoGenerateColumns="false" AllowFilteringByColumn="True" AllowSorting="true"   >                                                                                    
                        <ExpandCollapseColumn><HeaderStyle Width="20px"></HeaderStyle></ExpandCollapseColumn
                        <RowIndicatorColumn><HeaderStyle Width="20px" /></RowIndicatorColumn
                        <ExpandCollapseColumn><HeaderStyle Width="20px" /></ExpandCollapseColumn>                                                                                                 
                        <Columns>                        
               <%-- <telerik:GridDropDownColumn DataField="a" HeaderText="a" UniqueName="a"  />--%> 
               <telerik:GridDropDownColumn DataField="a" HeaderText="a" UniqueName="a" ListTextField="a" ListValueField="a" DataSourceID="SqlDataSource1"/>                 
               <telerik:GridBoundColumn    DataField="b" HeaderText="b" UniqueName="b" />                 
               <telerik:GridBoundColumn    DataField="c" HeaderText="c" UniqueName="c" />                 
               <telerik:GridBoundColumn    DataField="d" HeaderText="d" UniqueName="d" />   


 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
            { 
                string[] strArray = { "a", "e"}; 
                    GridEditFormItem item = (GridEditFormItem)e.Item; 
                    for (int k = 0; k < 2; k++) 
                    { 
                        GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)item.EditManager.GetColumnEditor(strArray[k]); 
                        editor.DataSource = (DataSet)Session["sesds"]; 
                        editor.DataTextField = strArray[k]; 
                        editor.DataValueField = strArray[k]; 
                        editor.DataBind(); 
                        editor.ComboBoxControl.AutoPostBack = true
                        editor.ComboBoxControl.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(ComboBoxControl_SelectedIndexChanged); 
                    } 
                     
            } 
             
        } 
 
 
protected void ComboBoxControl_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
        { 
            try 
            { 
                //string ElementID = Convert.ToString((sender as RadComboBox).SelectedItem.Text); 
                RadComboBox rad = (RadComboBox)o;                 
                GridEditableItem editedItem = (GridEditableItem)(o as RadComboBox).NamingContainer; 
                GridEditManager editMan = editedItem.EditManager; 
                foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns) 
                { 
                if (column is IGridEditableColumn) 
                {                    
                    IGridEditableColumn editableCol = (column as IGridEditableColumn); 
                    if (editableCol.IsEditable) 
                    { 
                        IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);                         
                        if (editor is GridTextColumnEditor) 
                        {                         
                            if ( rad.ID.ToLower() == "rcb_a") 
                            { 
                                if (column.UniqueName == "b") 
                                { 
                                    (editor as GridTextColumnEditor).Text = "Done"
                                } 
                                else if (column.UniqueName == "c") 
                                { 
                                    (editor as GridTextColumnEditor).Text = "ok"
                                } 
                                else if (column.UniqueName == "d") 
                                { 
                                    (editor as GridTextColumnEditor).Text = "ok1"
                                } 
                            } 
                            if (rad.ID.ToLower() == "rcb_e") 
                            { 
                                if (column.UniqueName == "f") 
                                { 
                                    (editor as GridTextColumnEditor).Text = "Done2"
                                } 
                                else if (column.UniqueName == "g") 
                                { 
                                    (editor as GridTextColumnEditor).Text = "ok2"
                                } 
                                else if (column.UniqueName == "h") 
                                { 
                                    (editor as GridTextColumnEditor).Text = "ok3"
                                    (editor as GridTextColumnEditor).Visible = false
                                } 
                            } 
                             
                        } 
                    } 
                 } 
              }             
            } 
            catch 
            { 
 
            } 
        } 


i can able to fetch values to bound columns but couldnt make it as non editable .
dynamically i want to set ,for some scenarios i need to make them as non editable ,n for some it shd be editable for that
only am not setting those properties on source


thanks in advance

7 Answers, 1 is accepted

Sort by
0
shankar mohan
Top achievements
Rank 1
answered on 03 Apr 2010, 08:40 AM
have attached screen shots
0
Mira
Telerik team
answered on 07 Apr 2010, 04:48 PM
Hello Shankar,

To implement the desired functionality I recommend that you set the ReadOnly property of the textboxes you want to make non-editable to true. You can find them in the Controls collection of the corresponding column editor.

I hope this helps.
 
Sincerely yours,
Mira
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
shankar mohan
Top achievements
Rank 1
answered on 08 Apr 2010, 08:56 AM
hello mira

if i set the read only property true then  the control disaapears, i wanna make the control as non editable{disabled}

foreach

 

(GridColumn column in RadGrid1.MasterTableView.RenderColumns)

 

{

.........................

if

 

(column.UniqueName == "b")

 

{

(editor

as GridTextColumnEditor).Text = "Done";

 

(column

as GridBoundColumn). readonly=true;

 

}

-----------------
i dont wanna use template controls ,cos i ve 50 columns so it takes much time to load,when i select value from drop down inside the grid it takes around 14 to 15 secs to load,

0
Mira
Telerik team
answered on 12 Apr 2010, 11:28 AM
Hello Shankar,

I suggest that you try using the following code to implement the desired functionality:
((editor as GridTextColumnEditor).Controls[0] as TextBox).ReadOnly = true;

Please let me know whether it helps.

Greetings,
Mira
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
shankar mohan
Top achievements
Rank 1
answered on 12 Apr 2010, 12:28 PM
hello mira

((editor

as GridTextColumnEditor).Controls[0] as RadTextBox).ReadOnly = true;

 


am getting err when i use the above code

""Specified argument was out of the range of valid values. Parameter name: index""

ok i ll use template controls for this but it takes much time to load,is their any possibilities to bind at client side

need client side event for dropdown template controls{rad:dropdown}   selected index changed event to bind values for template control{rad:textbox}

anyways thaks for the reply,
if possible reply for the above post else no probs
0
Mira
Telerik team
answered on 14 Apr 2010, 04:07 PM
Hello Shankar,

I have followed your scenario and prepared a sample project for you.
You can find it attached to this message.

Please take a look at it and let me know whether you find it useful.

All the best,
Mira
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
shankar mohan
Top achievements
Rank 1
answered on 15 Apr 2010, 09:37 AM
hello mira

thanks a lot it works fine
i can reduce  much loading time by using this

bye mira




Tags
Grid
Asked by
shankar mohan
Top achievements
Rank 1
Answers by
shankar mohan
Top achievements
Rank 1
Mira
Telerik team
Share this question
or