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

[Solved] ReadOnly item in CommandEventArgs

5 Answers 213 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 14 May 2008, 03:12 PM
Hello everyone,
    I'm just wondering if it is possible to have a readonly & hidden column which can be accessed in the GridCommandEventArgs. The reason for this is that I have an identity in a table, which is the DataSource of the grid, which is not supposed to be editted, but I also need that value in order to update the records in the database.
    Also, I have a column for passwords, and am wondering if there is an option to mask the data, in a way such that the GridCommandEventArgs.Item will recognize the text behind the mask, rather than redeading the characters. Using the DataFormatString = "********", the values are always ******** rather than the actual text, which is not good enough for my purposes since the database would recognize this value as different from the stored password.

Thanks :)

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 15 May 2008, 05:54 AM
Hi Chris,

You can use the DataKeyName property to access a GridColumn which is ReadOnly and hidden.

ASPX:
<MasterTableView PageSize="3" CommandItemDisplay="Top"   DataKeyNames="Reg"   Name="Master"     > 


CS:
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
        GridEditableItem editedItem = (GridEditableItem)e.Item; 
        
        //Get the primary key value using the DataKeyValue.      
        string Reg = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Reg"].ToString(); 
   } 
        


You can use the GridMaskedColumn to display PassWord fields.

ASPX:
<telerik:GridMaskedColumn HeaderText="PassWord" UniqueName="PassWord" DataField="PassWord" ></telerik:GridMaskedColumn> 

Thanks
Shinu.
0
Chris
Top achievements
Rank 1
answered on 16 May 2008, 01:32 PM
Hi, Shinu, thanks for the reply.

I got the UserID to work with the DataKeyNames you mentioned, thanks.
As for the masked item, I decided to just ignore it, since the passwords are using a hash, and can't be read anyways.

Thanks :)


... In a completely unrelated note; is it possible to get a grid to auto-post back on a selected index change? I've been looking, but haven't found a way to do so, and since when the selected index changes, I want to create a download, I can't wait for a postback to occur due to something else. I know I can do this with a 'Select' button column, but I'd prefer not to.
0
Wes Cloven
Top achievements
Rank 2
answered on 16 May 2008, 08:39 PM
I have a similar issue.  Your solution solved most of it and I was able to make a work around for the rest.  Thanks Shinu!

My question is can you get two hidden columns?  I have two columns definded as follows:

<telerik:GridBoundColumn 
    Visible="False" 
    ReadOnly="True" 
    DataField="ID" 
    UniqueName="IDColumn"
/>

<telerik:GridBoundColumn 
    Visible="False" 
    ReadOnly="True" 
    DataField="GroupID" 
    UniqueName="GroupIDColumn"
/>

Using the method Shinu showed I can get access to the first column but not the second.  My current work around involves making a call to the database to get the "GroupID" (a foriegn key) using the primary key "ID".  I would like to eliminate that extra call to the database.

Thanks,
Wes

0
Sebastian
Telerik team
answered on 17 May 2008, 05:53 AM
Hi Wes,

If you add both the ID and GroupID columns to the DataKeyNames collection of the master table, you should be able to avoid the extra call to the database and obtain the values from both hidden columns on update command using DataKeyValues.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Wes Cloven
Top achievements
Rank 2
answered on 18 May 2008, 03:05 AM
Thanks Stephen,

I missed the "s" on the end of DataKeyNames making it plural and didn't relize it was a collection.  I guess I need to open my eyes a bit.

I changed the value to:

DataKeyNames

="ID, GroupID"

and it now works like a champ.  No more extra calls to the database.

Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Wes Cloven
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or