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
186 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:Kamal Khaleefa
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:Kamal Khaleefa
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now