Solved

How can I make certain columns of certain  gridview rows be read only when data is bind and before Update?

Posted on 2015-01-30
7
235 Views
Last Modified: 2015-02-24
Hi, I'm using vs2012.
Depending on if certain column not null and no blank then I would like to make that row's 3 columns to be read only while leaving other column still editable when in Edit mode.  Same thing I would like to do when user in Edit mode change certain column's value then I would like to do the same.  How can I do that in Grivdview control's when it's binding to datasource and when user submits Update?
Thank you.
0
Comment
Question by:lapucca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 40582322
in the databind event make  like this

   If e.Row.RowType = DataControlRowType.DataRow Then




            Dim mycontrolID As Button or Linkbutton or ..etc = e.Row.findControl("yourcontrolID")

mycontrolID .Enabled=false

end if
0
 

Author Comment

by:lapucca
ID: 40584377
Is it in event RowDataBound that I do this?

If a checkbox comlumn is checked then I would like to make 3 of the columns of this row to be read only.  I'm not sure how your example code will do that.  Please elaborate.  Thank you.
0
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40585467
in loading row event of gridview  Try Like:

private void Mygridview _LoadingRow(object sender, DataGridRowEventArgs e)
        {
            var ObjRowdata = e.Row.DataContext as Sp_CustomerDetail;
            if (ObjRowdata.Customer== Customer_Care)
                e.Row.IsEnabled = false;
            else
                e.Row.IsEnabled = true;
        }
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 40585516
Hi
 Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
   
  If e.Row.RowType = DataControlRowType.DataRow Then
         Dim x As DataRowView = e.Row.DataItem
            Dim dt As DataTable = x.DataView.ToTable

  If dt.Rows(e.Row.DataItemIndex)("Your_Coloum_Name") Then
          e.Row.Enabled=false
end if

   End If
    End Sub

Open in new window

0
 

Author Comment

by:lapucca
ID: 40586814
King,
e.Row.Enabled=false
That would disable the entire row.  I only want certain cells during Edit to be not editable if a checkbox cell was checked. prior.  I'm able to do this in Row_editing event but it doesn't look nice because the textbox still shows up for these cells but users just can't type in it.

Thank you.
0
 
LVL 8

Accepted Solution

by:
Naitik Gamit earned 500 total points
ID: 40609611
To hide the value for some cells in the DataGridView control, we can handle the CellFormatting event for the DataGridView and set the FormatValue of the cell to some other character.
refer this link for clear solution:

https://social.msdn.microsoft.com/Forums/en-US/de0d8e0d-9101-4a45-a499-80fc282f73f4/clear-or-hide-specific-cell-in-datagrid-view
0
 

Author Closing Comment

by:lapucca
ID: 40628559
Thank you.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question