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

Grid values from DB

3 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yma
Top achievements
Rank 1
Yma asked on 05 Oct 2009, 05:33 PM
I have 2 dropdown boxes populating data from another 2 tables data. It requires  "Please select…" & data entry validation before database values as the first value.

 I have done it like this.But I have to valiate it and ,If user select "Please Select ... " Option retun and show a message again please select a value to update value.

 


<
telerik:GridDropDownColumn DataField="CompanyID" DataSourceID="SqlDataSource2" EditFormColumnIndex="5" HeaderText="Company" ListTextField="CompanyName" ListValueField="CompanyID"  EnableEmptyListItem = "true" EmptyListItemText="--Please select Company--" EmptyListItemValue="0" UniqueName="CompanyID" ColumnEditorID="GridDropDownColumnEditor1">

 

 

 

</telerik:GridDropDownColumn>

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Oct 2009, 06:31 AM
Hello Yma,

You can add a RequiredFieldValidator to the corresponding editors as shown below:
c#:
 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
      if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)editItem.EditManager.GetColumnEditor("CompanyID");             TableCell cell = (TableCell)editor.ComboBoxControl.Parent; 
 
            RequiredFieldValidator validator = new RequiredFieldValidator(); 
            editor.ComboBoxControl.ID = "IDToValidate"
            validator.ControlToValidate = editor.ComboBoxControl.ID; 
            validator.InitialValue = "--Please select Company--"
            validator.ErrorMessage = "please select a value to update"
            cell.Controls.Add(validator);     
 
        }  
   } 

Hope this helps..
Princy.
0
Yma
Top achievements
Rank 1
answered on 06 Oct 2009, 02:47 PM
Thank you very much for the reply.

I tried this.But seems not working. I want to add first "--Please select Company--  "  and populate values from tha database from second item. If user select "--Please select Company--  " as the first item we should not update the record and it should return with a message saying " please select a value to update "

What do you mean by  IDToValidate? .Isnt it the  CompanyID?

 

Thanks Again.
0
Eric Skaggs
Top achievements
Rank 2
answered on 19 Oct 2009, 03:29 PM
Hi Yma,

The IDToValidate should just be something that makes sense so that the comboboxcontrol has an ID.  Here's my C# source for the ItemCreated event that works great for me.
protected void grdProcessingInline_ItemCreated(object o, GridItemEventArgs e)  
        {  
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
            {  
 
                GridEditableItem editItem = (GridEditableItem)e.Item;  
                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)editItem.EditManager.GetColumnEditor("ProcessingTypeDesc");   
                TableCell cell = (TableCell)editor.ComboBoxControl.Parent;  
 
                RequiredFieldValidator validator = new RequiredFieldValidator();  
                editor.ComboBoxControl.ID = "cboProcessType";  
                validator.ControlToValidate = editor.ComboBoxControl.ID;  
                validator.ErrorMessage = "Required:  Processing Type";  
                cell.Controls.Add(validator);   
            }  
        } 

Hope that helps!

Eric Skaggs
Tags
Grid
Asked by
Yma
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Yma
Top achievements
Rank 1
Eric Skaggs
Top achievements
Rank 2
Share this question
or