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

Binding Programmatically

6 Answers 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Silvio Silva Junior
Top achievements
Rank 2
Silvio Silva Junior asked on 24 Mar 2010, 10:17 PM
Hello guys.

I'm trying to use this example (without image column, very simple), but I'm setting its datasource by a c# method. The grid is binded correctly and the action started by the "add new record" button, showing all fields to insert a new record. However, the edit and delete button gave me this exception:

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

and the insert button do nothing.

First: How can I to know the name of controls showed in the insert action?
Second: What's the event fired by Edit and the delete button? I tryed to put a breakpoint in the: RadGrid1_UpdateCommand, RadGrid1_EditCommand, RadGrid1_ItemDeleted, RadGrid1_DeleteCommand, but the system doesn't break at breakpoint.

Tx in advance.

Regards.




6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Mar 2010, 01:37 PM
Hi,

I found following forum links which discusses about similar error. Go through the links which might help in resolving the exception:

http://www.telerik.com/community/forums/aspnet/grid/error-when-using-buttontype-imagebutton.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/command-item-and-invalid-postback-or-callback-argument.aspx

1. You can access controls in the insert form by using the ColumnUniqueName. Checkout the sample code below:

C#:

protected
 void RadGrid3_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
  if ((e.Item.OwnerTableView.IsItemInserted)) 
  { 
   TextBox txtName =  ((TextBox)((GridEditFormInsertItem)e.Item)["ColumnUniqueName"].Controls[0]) 
  } 
Also checkout the documentation: Accessing cells and rows

Thanks,
Princy.
0
Silvio Silva Junior
Top achievements
Rank 2
answered on 25 Mar 2010, 01:49 PM
0
0
Silvio Silva Junior
Top achievements
Rank 2
answered on 25 Mar 2010, 10:11 PM
One more question.

I have a GridDropDownColumn like:

<telerik:GridDropDownColumn  
DataField="A017_dsc_tip"  
HeaderText="Tipo"  
UniqueName="A017_dsc_tip"  
ListDataMember="T017_tipo_telefone"  
SortExpression="A017_dsc_tip"  
ListTextField="A017_dsc_tip"  
ListValueField="A017_dsc_tip" 
> 
and I'm trying to bind the dropdown using this snipet code:
GridEditableItem item = e.Item as GridEditableItem;             
RadComboBox A017_dsc_tip = ((RadComboBox)((GridEditFormItem)e.Item)["A017_dsc_tip"].Controls[0]); 
entities = new GEDEntities(); 
ObjectQuery<T017_TIPO_TELEFONE> query = entities.T017_TIPO_TELEFONE; 
A017_dsc_tip.DataSource = query.AsQueryable(); 
A017_dsc_tip.DataBind(); 
A017_dsc_tip.DataTextField = "A017_dsc_tip"
A017_dsc_tip.DataValueField = "A017_cod_tip"

The source have no problems, with all results. I have no aplications errors, but, my dropdown show only the first  result.

Wha'ts wrong?

Tx.

Regards.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 26 Mar 2010, 06:18 AM
Hi Silvio,

I tried the approach described in the documentation and got it worked.Give a try with this code and see if it helps.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
        GridEditableItem editedItem = e.Item as GridEditableItem; 
        GridEditManager editMan = editedItem.EditManager; 
        GridDropDownListColumnEditor editor = 
        editMan.GetColumnEditor("GridDropDownColumn1"as GridDropDownListColumnEditor; 
        editor.DataSource = getUserDetails("select city from customers where city like '%Be%';"); 
        editor.DataTextField = "city"
        editor.DataValueField = "city"
        editor.DataBind(); 
    }
}

Regards
Shinu
0
Silvio Silva Junior
Top achievements
Rank 2
answered on 26 Mar 2010, 03:22 PM
Tx a lot Princy and Shinu.

Problem solved.
Tags
Grid
Asked by
Silvio Silva Junior
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Silvio Silva Junior
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or