Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
247 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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