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

grid edit mode

9 Answers 225 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Troika
Top achievements
Rank 1
Troika asked on 29 Jul 2013, 09:19 AM
I have a gridview with auto generate columns and it shows several data what I need is when I edit a record it hows everything with textbox I need on a specific field to show a combobox instead and that combobox must have a datasiurce and changes must be saved on update
also other field need to show a label instead of textbox.

in design mode I went on edit template but there I cant field any fields to delete the textbox and put a combobox like with the default gridview of visual studio...

9 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Jul 2013, 10:53 AM
Hi Troika

Please try the following code snippet,to make one column as RadComboBox,and the rest as Labels.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"  AutoGenerateEditColumn="true"
    OnItemDataBound="RadGrid1_ItemDataBound" >
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       foreach (GridBoundColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
       {
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               GridEditableItem item = (GridEditableItem)e.Item;
               TextBox txt = (TextBox)item[col.UniqueName].Controls[0];
               string value = txt.Text;
               txt.Visible = false;
               if (!(col.DataField == "EmployeeID")) // Avoiding the Column which is to be a ComboBox
               {
                   Label newlabel = new Label();
                   newlabel.Text = value;               
                   newlabel.ID = "lnk" + Guid.NewGuid(); //Generating ID's for all label Controls
                   item[col.UniqueName].Controls.Add(newlabel);              
               }
               else
               {
                   RadComboBox combo = new RadComboBox();
                   combo.SelectedValue = value;
                   combo.DataSourceID = "SqlDataSource1";
                   combo.DataTextField = "EmployeeID";
                   combo.DataValueField = "EmployeeID";              
                   combo.ID = "lnk" + Guid.NewGuid(); //Generating ID for combobox
                   item[col.UniqueName].Controls.Add(combo);             
               }
           }
       }
   }

Thanks,
Princy

0
Troika
Top achievements
Rank 1
answered on 31 Jul 2013, 09:05 AM

i actually need 3 combobox and all the rest label maybe with a foreach on this if is a simple way to do it

if (!(col.DataField == "Função"))

 then i ned to have diferente datasoureces for the combobox
and one datatype is of type datapicker (calenmdar) not textbox so i get na error here

TextBox txt = (TextBox)item[col.UniqueName].Controls[0];


then how can i pick the new values of the items and save it on update buton click?

best thing is to transform any type in label and avoid some by specifiing column name as you do

sorry for the error
0
Eyup
Telerik team
answered on 01 Aug 2013, 10:30 AM
Hi Troika,

Generally, you can simply use GridDropDownColumn which will  automatically generate a combobox as its edit mode control. Furthermore, you can define a GridDropDownListColumnEditor to control its appearance and settings. An alternative approach would be to create a GridTemplateColumn with a combobox in its EditTemplate.

The third option would be to create your column editors manually and configure them according to your own preferences:
http://www.telerik.com/help/aspnet-ajax/grid-custom-editors.html

I have attached 2 sample web sites demonstrating how to implement custom grid editors.

I hope this will prove helpful. Please choose the approach which best suits your own requirements and let us know about the result.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Troika
Top achievements
Rank 1
answered on 01 Aug 2013, 02:28 PM
i think that is too much complicated to just put a combobox in edit mode so i found this but i get error it says cant find RoleId

<MasterTableView>

 

<Columns >

<telerik:GridDropDownColumn DataSourceID="sql_ds_funcao" DataField="RoleId" ListTextField="RoleName" UniqueName="Função" DropDownControlType="RadComboBox">

</telerik:GridDropDownColumn>

 

</Columns>

</MasterTableView>

or if there is same way to do it linke in teh asp.net grid we have all fields and we just make a drag n drop to put a combo in edit mode and associate with datasource
0
Troika
Top achievements
Rank 1
answered on 01 Aug 2013, 03:18 PM
i really need to get this solved asap

so i will explain better i haev a grid with all usernames registereda nd otehr info.

username -> transform tetxtbox in editmode
email -> textbox
UserRoles -> checkbox list with checked roles of user
LastLoginDate -> label
Aproved ->editable checkbox
IsLocked out -> editable checkbox
must get values to get membership update user

so if values changes it updates on db


also in normal view (not edit) the proved and is locked out apper as true/false could it be changed to checkbox because
with this

MembershipUserCollection Users = Membership.GetAllUsers();

 appears the checkbox but when i get it on arraylist i changes to true/false
0
Eyup
Telerik team
answered on 02 Aug 2013, 08:30 AM
Hi Troika,

You can use several possible approaches to achieve the requested functionality:
 - EditItemTemplates:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultcs.aspx
- EditFormTemplate:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/templateformupdate/defaultcs.aspx
- EditForm UserControl:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx

I hope this will prove helpful.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Troika
Top achievements
Rank 1
answered on 02 Aug 2013, 12:06 PM
how can i have in editmode a checkbox list , in normal view i have a string then in edit i want to have that checklist and pick values on update button click
0
Eyup
Telerik team
answered on 02 Aug 2013, 01:46 PM
Hi Troika,

Please refer to the following section for accessing and modifying the generated edit form controls:
( Section Accessing controls in edit/insert mode )
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

Let us know if it helps you.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Troika
Top achievements
Rank 1
answered on 02 Aug 2013, 08:30 PM
d
Tags
Grid
Asked by
Troika
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Troika
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or