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

[Solved] Prevent items from appearing in EditForm

5 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 25 Apr 2008, 02:06 PM
Hi,

I have a RadGrid which has several columns visible:

Name, Date Added, Comment

When they go into Edit Mode, I dont want Name to be in the form as I need to capture the users logon ID from the HTTPContext and automatically store this in the underlying table rather then the name.

In other words:

In the COMMENTS table I am storing the USER_ID.

In the recordset coming back, I am joining COMMENTS to USERS table to present the Name in the RadGrid.

When they go into Edit Mode....I dont want Name to be editable, because I actually want to capture the users logon ID and pass this in.

I am using an ObjectDataSource and my Insert is failing because a method with a signature which includes a "NAME" parameter cant be found:

In My ObjectDataSource

Public Sub AddComment( _

ByVal DASHBOARD_PAGE_ID As Long, _

ByVal LOGON_ID As String, _

ByVal DATE_ADDED As String, _

ByVal COMMENTARY As String, _

ByVal LIVE As Boolean, _

ByVal PROMOTED As Boolean, _

ByVal RESPONSIBLE_PERSON As String, _

ByVal OUTCOME As String)

' Create Connection

Dim con As New SqlConnection(_conString)

'Create Command

Dim cmdText As String = "SP_CLIN_DASHBOARD_ADD_COMMENT" ' This requires a parameter of DashboardPage_ID

Dim cmd As New SqlCommand(cmdText, con)

cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.AddWithValue(

"@DASHBOARD_PAGE_ID", DASHBOARD_PAGE_ID)

cmd.Parameters.AddWithValue(

"@LOGON_ID", LOGON_ID)

cmd.Parameters.AddWithValue(

"@DATE_ADDED", DATE_ADDED)

cmd.Parameters.AddWithValue(

"@COMMENTARY", COMMENTARY)

cmd.Parameters.AddWithValue(

"@LIVE", LIVE)

cmd.Parameters.AddWithValue(

"@PROMOTED", PROMOTED)

cmd.Parameters.AddWithValue(

"@RESPONSIBLE_PERSON", RESPONSIBLE_PERSON)

cmd.Parameters.AddWithValue(

"@OUTCOME", OUTCOME)

cmd.ExecuteNonQuery()

End Sub



Where I am capturing the LOGON_ID and passing it in:

Protected Sub srcComments_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles srcComments.Inserting

e.InputParameters.Item(

"DASHBOARD_PAGE_ID") = Session("DASHBOARD_PAGE_ID")

e.InputParameters.Item(

"LOGON_ID") = HttpContext.Current.User

e.InputParameters.Item(

"DATE_ADDED") = Now()

End Sub



Thanks



5 Answers, 1 is accepted

Sort by
0
Vladimir
Top achievements
Rank 1
answered on 26 Apr 2008, 07:27 AM
Hi Stephen,

You can set Name column to be ReadOnly. Here is an example:

<telerik:GridBoundColumn DataField="Name"
ReadOnly="true"..
0
Shinu
Top achievements
Rank 2
answered on 28 Apr 2008, 01:09 PM
Hi,

You can also try  the code snippet below to hide the required columns in the edit form:

CS:
 protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
          foreach (GridDataItem item in RadGrid1.EditItems)  
        {  
            GridEditableItem itemToEdit =  
            (item.OwnerTableView.EditMode == GridEditMode.InPlace) ?  
            (GridEditableItem)item : (GridEditableItem)item.EditFormItem;  
            itemToEdit["ShipName"].Visible = false;  
             
        }  
    } 


Thanks,
Shinu
0
Stephen
Top achievements
Rank 1
answered on 28 Apr 2008, 01:22 PM
Thanks,

My issue is also to prevent the parameters being passed to the ObjectDataSource Update and Delete methods.  Will these methods work for this?

Thanks

Stephen
0
Yavor
Telerik team
answered on 29 Apr 2008, 08:17 AM
Hi Stephen,

If the EditField is not visible, no data will be passed to the underlying datasource object.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Stephen
Top achievements
Rank 1
answered on 29 Apr 2008, 02:32 PM
Thanks.

Great product and great support by the way!
Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Vladimir
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Stephen
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or