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

Placing grid in edit mode on initial load

16 Answers 297 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 06 Jan 2009, 04:24 PM
My environment consists of VS2005, Framework 2.0 and Telerik RadControls Q1 2007.

My client wishes to display a grid that is initially in edit mode. All rows displayed must be editable (AllowMultiRowEdit is true) but only 3 of the columns in each row will be editable.

No command column will be displayed  on each row in the grid (i.e. no insert/update/delete link or button)

When the user finishes editing the data, he will click a command button in the grid header to update the changed rows in the grid (using AJAX).

The objective is to provide a quick way for a user to view several rows of data and perform actions on some or all rows and then update all changed rows.

Any suggestions for the best approach to the process or any sample code would be greatly appreciated.


16 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 07 Jan 2009, 04:32 AM
Hi John,

It is possible to set the entire RadGrid in edit mode using trying following code snippet.

CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    foreach (GridDataItem item in RadGrid1.Items) 
    { 
        item.Edit = true
        RadGrid1.Rebind(); 
    }  

Set the ReadOnly property for all the other columns except the required field to prevent the editing. Add the button in CommandItemTemplate so that you can perform batch update on clicking that. Please refer the following link to online documentation for performing batch updates.
Performing batch updates

Thanks,
Princy.
0
Peter
Top achievements
Rank 1
answered on 09 Feb 2009, 09:20 PM
I have a somewhat similar application question on putting - and keeping - the entire grid in edit mode.  We have an old application we are replacing, and one page has a grid that contains several columns, some text fields and some combo boxes.  Will the sample code you posted show all of the combo boxes at once as combos and not just a text box, and if the user changes one of the dropdowns, will it automatically leave edit mode, or can I force it to stay in edit mode (and therefore showing as a dropdown.)?

Thanks
0
Princy
Top achievements
Rank 1
answered on 10 Feb 2009, 05:44 AM
Hello Peter,

The code I have provided above should put all the rows on your grid in EditMode and would remain in EditMode even if you change selection on a dropdown. I'm not sure as to what is your requirement exactly. GridBoundColumns display textboxes when the grid is in EditMode and if you want to display comboboxes while in EditMode you can use a GridDropDownColumn or a GridTemplateColumn with a ComboBox in its EditItemTemplate as shown below.
aspx:
<telerik:GridDropDownColumn UniqueName="ComboBox" HeaderText="ComboBox" DataSourceID="SqlDataSource1" DataField="ProductName" >         
 </telerik:GridDropDownColumn> 
 
<telerik:GridTemplateColumn UniqueName="TemplateColumn">  
        <ItemTemplate>  
            <telerik:RadComboBox ID="RadComboBox1" DataTextField="ProductName" DataSourceID="SqlDataSource1"  runat="server">  
            </telerik:RadComboBox>           
        </ItemTemplate>  
        <EditItemTemplate>  
            <telerik:RadComboBox ID="RadComboBox2" DataTextField="ProductName" DataSourceID="SqlDataSource1" runat="server">  
            </telerik:RadComboBox>  
        </EditItemTemplate>  
 </telerik:GridTemplateColumn>  

Thanks
Princy.
0
Peter
Top achievements
Rank 1
answered on 10 Feb 2009, 04:43 PM
Thanks, I will try that code.  Our requirement is exactly as you stated in your first sentence, always in edit mode and always showing dropdowns as dropdowns and never as text fields.

Peter
0
Myriam
Top achievements
Rank 1
answered on 13 May 2009, 08:06 PM
Hello John

I'm interresing to the code that does:
"When the user finishes editing the data, he will click a command button in the grid header to update the changed rows in the grid (using AJAX)."

Could you send me the code of that button please. This would be very userful for me!!!
Thank you!
0
Iana Tsolova
Telerik team
answered on 14 May 2009, 07:25 AM
Hello Myriam,

Please review this online demo which shows how you could customize the grid CommandItem and place there buttons for editing/updating/deleting items and all of this with RadAjax.

I hope this helps.

Greetings,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Myriam
Top achievements
Rank 1
answered on 20 May 2009, 01:25 PM
Hello
what if I would like to insert instead update my data using data entered in the editabled fields but also in the non-editabled items on the same row?
Thank you
0
Iana Tsolova
Telerik team
answered on 20 May 2009, 02:43 PM
Hello Myriam,

Could you please elaborate a bit on your scenario? Do you mean that you want to put some grid items into edit mode and then when the Update button is clicked, instead of updating the existing items in the database, you need to add them as new Items in the data table?

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Myriam
Top achievements
Rank 1
answered on 20 May 2009, 02:55 PM
Yes this is it.
The only difference on what you said is that I have to add them as new items in another table.
0
Iana Tsolova
Telerik team
answered on 21 May 2009, 11:29 AM
Hi Myriam,

In this case you can handle the grin ItemCommand event and there check if the command fired equals to the CommandName of the Update button (it is "UpdateEdited" in this example). Then you could perform batch insert as the batch update shown here:

protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
   {  
       if (e.CommandName == "<UpdateButtonCommandName here>")  
       {  
           foreach (GridEditableItem editedItem in RadGrid1.EditItems)  
           {                 
               Hashtable newValues = new Hashtable();  
               //The GridTableView will fill the values from all editable columns in the hash  
               e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);  
               //perform inserting data into desired table here                  
               editedItem.Edit = false;  
           }  
       }  
       RadGrid1.Rebind();  
   }  
 

Let me know if this helps.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Myriam
Top achievements
Rank 1
answered on 21 May 2009, 12:41 PM
Thank you very much for you time.
How can I get the value from the row?  For example I need the row id "Row1", "Row3".
Thanks again
I really appreciate
0
Myriam
Top achievements
Rank 1
answered on 21 May 2009, 12:58 PM
I tried this:
    SqlDsIntervenant.InsertCommand = String.Format("INSERT INTO T_COMPTENCES_TRANVERSALES (FICHE, MAT, GRP, NO_INTERV, COMPTENCES, NOM, PRENOM) VALUES (" & newValues("FICHE") & ",'" & newValues("MAT") & "', '" & newValues("GRP") & "', '" & newValues("NO_INTERV") & "', '" & newValues("COMPTENCES") & "','" & newValues("NOM") & "','" & newValues("PRENOM") & "')"
And it gives me an error.
Here is what the insertcommand value contain:
"INSERT INTO T_COMPTENCES_TRANVERSALES (FICHE, MAT, GRP, NO_INTERV, COMPTENCES, NOM, PRENOM) VALUES (,'', '', '', '','','')"

What,s wrong?
0
Iana Tsolova
Telerik team
answered on 22 May 2009, 10:10 AM
Hello Myriam,

I went through your insert command and it looks fine to me. Could you please specify what is the error you received?

Additionally, you can review this helps topic for m more information on accessing grid cells and rows.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Myriam
Top achievements
Rank 1
answered on 25 May 2009, 12:29 PM

Hello Iana

The error I received is because I have no values in the newValues("FICHE") and the others field
 Why do I have nothing in the newValues object?

0
Myriam
Top achievements
Rank 1
answered on 25 May 2009, 12:56 PM
Hello

Iana
As I can see, this is caused by this

  Private Sub RadGrid1_ColumnCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated  
        If (e.Column.ColumnType = "GridBoundColumn"AndAlso (Left(e.Column.UniqueName, 3) <> "TRA"Then 
            Dim bndcol As GridBoundColumn = DirectCast(e.Column, GridBoundColumn)  
            bndcol.[ReadOnly] = True 
          
        End If 
 
    End Sub 
 
 Private Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated  
         
        e.Item.OwnerTableView.GetColumn("ID_ECO").Display = False 
        e.Item.OwnerTableView.GetColumn("NO_INTERV").Display = False 
        e.Item.OwnerTableView.GetColumn("ANNEE").Display = False 
        e.Item.OwnerTableView.GetColumn("NOM").Display = False 
        e.Item.OwnerTableView.GetColumn("PNOM").Display = False 
    End Sub 
If I put this code with a ' before the line, this is working, I got something in the newValues object. But I need to hide them and put them readonly.
Does somebody know a workaround for this please?
Thank you
0
Myriam
Top achievements
Rank 1
answered on 25 May 2009, 01:14 PM
Ok!
Now this is solved!!!
HEre is my code
   Private Sub RadGrid1_ColumnCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated  
        If (e.Column.ColumnType = "GridBoundColumn"AndAlso (Left(e.Column.UniqueName, 3) <> "TRA"AndAlso e.Column.UniqueName <> "NOM" AndAlso e.Column.UniqueName <> "PNOM" AndAlso e.Column.UniqueName <> "FICHE" AndAlso e.Column.UniqueName <> "ID_ECO" AndAlso e.Column.UniqueName <> "ANNEE" AndAlso e.Column.UniqueName <> "NO_INTERV" Then 
            Dim bndcol As GridBoundColumn = DirectCast(e.Column, GridBoundColumn)  
            bndcol.[ReadOnly] = True 
 
        End If 
 
    End Sub 
 
 
    Private Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated  
         
        e.Item.OwnerTableView.GetColumn("ID_ECO").Display = False 
        e.Item.OwnerTableView.GetColumn("NO_INTERV").Display = False 
        e.Item.OwnerTableView.GetColumn("ANNEE").Display = False 
        e.Item.OwnerTableView.GetColumn("NOM").Display = False 
        e.Item.OwnerTableView.GetColumn("PNOM").Display = False 
        e.Item.OwnerTableView.GetColumn("FICHE").Display = False 
    End Sub 
The problem was the readonly property. But this the display=false, now I don't see them and this is perfect!!
Thank you very much for your help!
I rreeeaaaaalllllyyyyy appreciate it!
thanks again!
I'm soooooo happy now!
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Myriam
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or