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

[Solved] Google-Like suggest

3 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 13 Jun 2008, 02:18 AM

I'm trying out the "Google-Like" suggest from KB Article ID# 696. I have it implmented and working correctly per the article.

I added a GridEditCommandColumn to my RadGrid and and the column doesn't show up. When I click "Add Record" at the top the column then displays and then if I hit cancel it stays it will stay displayed, except it'll display in the first column (in my case ItemID).

When using the "Google-Like" suggest, do I need to write my own code for Insert/Update/Delete and put it in InsertCommand, UpdateCommand, and DeleteCommand?

I would also like to add in some RadTextBoxes and NumericTextBoxes for some of the columns using the InPlace EditMode, do I need to write everything out by hand as well?

Thanks,

Brett

 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Jun 2008, 04:36 AM
Hi Brett,

You can use a GridTemplateColumn and place RadNumericTextBox/RadTextBox in its EditItemTemplate.

<telerik:GridTemplateColumn UniqueName="TempCol1" HeaderText="TempCol1" > 
         <EditItemTemplate> 
                <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server"> 
                </telerik:RadNumericTextBox> 
            </EditItemTemplate> 
          </telerik:GridTemplateColumn> 
     <telerik:GridTemplateColumn UniqueName="TempCol2" HeaderText="TempCol2" > 
           <EditItemTemplate> 
               <telerik:RadTextBox ID="RadTextBox1" runat="server"> 
               </telerik:RadTextBox> 
           </EditItemTemplate> 
          </telerik:GridTemplateColumn> 

Go through the following help document links to get information about how you can perform Insert/Update/Delete with RadGrid.

Automatic operations
Insert/Update/Delete at database level with queries

Thanks
Shinu.
0
Brett
Top achievements
Rank 1
answered on 13 Jun 2008, 07:27 AM

Shinu Thank you for your quick response.

I followed the Insert/Update/Delete at database level with queries documentation and I was able to get Updates to work correctly, however, when I tried it with an insert I get:

Unable to cast object of type 'Telerik.Web.UI.GridDataInsertItem' to type 'Telerik.Web.UI.GridEditFormInsertItem' on:

GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;

Which is the first line in my RadGrid1_InsertCommand

Then if I use a GridTemplateColumn and place a RadTextBox in its EditItemTemplate I get:

The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

In case anyone is listening:

It seems like a lot of work to get the "Google-Like" suggest working; it would be a nice feature to have added where you can enable it out of the box. When I was evaluating different control suites a few others had a feature similar to this (although not as cool) out of the box. Knowing this I still went with Telerik because the controls are way better, the documentation is very good (I'd say the best because I was able to get the Telerik controls working :) ), and overall it's a way better product, add in Telerik Reporting, and it's really outstanding IMO.

It would be a nice feature to have when you set "AllowFilteringByColumn" to True, you can also select, "Google-Like Filtering" to true, or "Filter By DropDown" or a few other options for filtering and it would automatically do this for you. 

The capabilities of the filtering out of the box are really nice and give quite a lot of different options, but sometimes when you have too many options it makes it confusing to people so it would be a nice feature to have where you can cut down the options to make it a little bit easier for them.

Thanks,

Brett

0
Princy
Top achievements
Rank 2
answered on 13 Jun 2008, 11:30 AM
Hi Brett,

Try inserting the data as shown below.

CS:
protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)     
   {     
       //Get the GridDataInsertItem of the RadGrid       
       GridDataInsertItem insertedItem = (GridDataInsertItem)e.Item;     
   
       //string EmployeeID = (insertedItem["EmployeeID"].Controls[0] as TextBox).Text;     
   
       string LastName = (insertedItem["LastName"].Controls[0] as TextBox).Text;     
       string FirstName = (insertedItem["FirstName"].Controls[0] as TextBox).Text;     
       string Title = (insertedItem["Title"].Controls[0] as TextBox).Text;     
       string Address = (insertedItem["Address"].Controls[0] as TextBox).Text;     
       string City = (insertedItem["City"].Controls[0] as TextBox).Text;     
           
       try     
       {     
           //Open the SqlConnection       
           SqlConnection.Open();     
           //Update Query to insert into  the database        
           string insertQuery = "INSERT into  Employees(LastName,FirstName,Title,Address,City) values('" + LastName + "','" + FirstName + "','" + Title + "','" + Address + "','" + City + "')";     
           SqlCommand.CommandText = insertQuery;     
           SqlCommand.Connection = SqlConnection;     
           SqlCommand.ExecuteNonQuery();     
           //Close the SqlConnection       
           SqlConnection.Close();     
   
   
       }     
       catch (Exception ex)     
       {     
           RadGrid1.Controls.Add(new LiteralControl("Unable to insert Employee. Reason: " + ex.Message));     
           e.Canceled = true;     
       }       
   
   }     
        
}     

Princy.
Tags
Grid
Asked by
Brett
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brett
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or