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
226 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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
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.…

728 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