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

Problem with edit-mode when using OnItemsRequested for a combobox

1 Answer 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cecilie Nordbø
Top achievements
Rank 1
Cecilie Nordbø asked on 06 Aug 2010, 12:25 PM
Hi.
I have a grid with a combobox that use OnItemsRequested, to get only the values that is not already in the grid. But the problem is that i can not get a record in edit mode when using OnItemsRequested. If I instead use the combobox datasource, the edit mode works fine but then i get all the values from the database table. In edit-mode the user should not have the possibility to change the value and thee combobox will be disabled. (The OnItemsRequeste methode will not fill the combobox values with the choosen value from insert.) So how can i work it out?

The following code i am using is:

protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
      {
          var users = MtUserAccountBiz.GetMtUserWithNoAccountMapping();
 
          var comboBox = (RadComboBox)sender;
          comboBox.Items.Clear();
          foreach (var user in users)
          {
              var item = new RadComboBoxItem();
              item.Text = user.UserNumber + " " + user.FirstName + " " + user.LastName;
              item.Value = user.UserNumber.ToString();
              comboBox.Items.Add(item);
          }          
      }


<Columns>       
  <telerik:GridTemplateColumn UniqueName="UserNumber" DataField="UserNumber" HeaderText="Bruker"  >
    <ItemTemplate><%#DataBinder.Eval(Container.DataItem,"UserNumber")%></ItemTemplate>
    <EditItemTemplate>
      <telerik:RadComboBox DataTextField="UserNumber" DataValueField="UserNumber" EnableLoadOnDemand="True" ID="RadComboBox1"   HighlightTemplatedItems="true"
            runat="server" Height="160px" Width="220px" SelectedValue='<%#Bind("UserNumber") %>'  
                   OnItemsRequested="RadComboBox1_ItemsRequested" AutoPostBack="true">                   
      </telerik:RadComboBox>
    </EditItemTemplate>
  </telerik:GridTemplateColumn>
  <telerik:GridNumericColumn  DataField="Account" HeaderText="Reskontro"  UniqueName="Account">   </telerik:GridNumericColumn>
  <telerik:GridEditCommandColumn CancelText="Avbryt" EditText="Endre" InsertText="Sett inn" UpdateText="Oppdater"></telerik:GridEditCommandColumn>
                     
    </Columns>

1 Answer, 1 is accepted

Sort by
0
Cecilie Nordbø
Top achievements
Rank 1
answered on 09 Aug 2010, 11:42 AM
I find it out from a answer from another thread i have started. The solution from Carlos Contreras work for this case too:

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{                    
   if (e.CommandName == "InitInsert") HideRow(false, "UserNumber");
   if (e.CommandName == "Edit") HideRow(true, "UserNumber"); 
}
 
protected void HideRow(bool hidden, string fieldName)
{
   var column = (GridTemplateColumn)RadGrid1.MasterTableView.GetColumn(fieldName);
   if (column != null)
   {
          column.ReadOnly = hidden;
           RadGrid1.MasterTableView.Rebind();
   }
}
Tags
Grid
Asked by
Cecilie Nordbø
Top achievements
Rank 1
Answers by
Cecilie Nordbø
Top achievements
Rank 1
Share this question
or