radGrid bound to dataset : primary editable?

3 posts, 1 answers
  1. seriallabs
    seriallabs avatar
    3 posts
    Member since:
    Apr 2008

    Posted 28 Jan 2009 Link to this post

    Hello, I've got a lot of issues with RadGrid. I suppose I don't use it in a standard way ?
    Well, I have first a simple question:
    I have some dataset created on the fly, and I link a radGrid to it. (to its first table)
    One of the columns is a classic "Id" auto-inc primary key, which is set to ReadOnly

    So when the user edits one row, I would like the "id" column ot be "not editable"
    BUT the IsEditable property is a "get" property, which returns true ...

    Relevant Code:
    <telerik:RadGrid ID="RadGrid1" runat="server"   
                AllowSorting="True"   
                   
                AutoGenerateDeleteColumn="True"   
                AutoGenerateEditColumn="True"             oncolumncreated="RadGrid1_ColumnCreated"   
                ondatabound="RadGrid1_DataBound"   
                onneeddatasource="RadGrid1_NeedDataSource"   
                   
                onitemupdated="RadGrid1_ItemUpdated" onrowdrop="RadGrid1_RowDrop"   
                onupdatecommand="RadGrid1_UpdateCommand"   
                AllowMultiRowEdit="True"    
                  
                > 
     
    <MasterTableView DataKeyNames ="cID" EditMode="InPlace">  
    ... 
     if (mydt.PrimaryKey == null || mydt.PrimaryKey.Length<1)  
            { // if there is no primary  
                DataColumn col = new DataColumn("cID"typeof(int));  
                col.AutoIncrement = true;  
                  
                mydt.Columns.Add(col);  
                int rc = 0;  
                foreach (DataRow drw in mydt.Rows){ rc++; drw["cID"] = rc;}//fill for existing rows  
                mydt.PrimaryKey = new DataColumn[] { mydt.Columns["cID"] };  
                  
            }  
            
            nDS.Tables[0].Columns["cID"].ReadOnly = true;  
                  
            RadGrid1.DataSource = nDS.Tables[0];  
            RadGrid1.AutoGenerateColumns = false;  
     
            GridBoundColumn boundColumn;  
            boundColumn = new GridBoundColumn();  
            RadGrid1.MasterTableView.Columns.Add(boundColumn);  
            boundColumn.DataField = "cID";  
            boundColumn.HeaderText= "id";  
     
            bool ised = boundColumn.IsEditable; //RETURNS TRUE ! 


    bool
    ised = boundColumn.IsEditable; // RETURNS TRUE !! and the corresponding field is shown while editing.

    How to set the radGrid column to "not editable" so that no entry textbox is generated ?

    Thank you!

     

     

     

     

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2009 Link to this post

    Hello Olivier,

    Inorder to make a column non-editable, you can set the ReadOnly property of the column to true as shown below:
    cs:
            GridBoundColumn boundColumn; 
            boundColumn = new GridBoundColumn(); 
            RadGrid1.MasterTableView.Columns.Add(boundColumn); 
            boundColumn.DataField = "cID"
            boundColumn.HeaderText = "id"
            boundColumn.ReadOnly = true

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. seriallabs
    seriallabs avatar
    3 posts
    Member since:
    Apr 2008

    Posted 29 Jan 2009 Link to this post

    Hello Princy,
    Thank you so much.
    it works perfectly. Actually, it was quite obvious. The fact is a did not see such property in the doc of radGrid, and have searched many hours in other directions..
Back to Top