Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

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

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
lapucca
Asked:
lapucca
  • 3
  • 2
  • 2
1 Solution
 
Kamal KhaleefaInformation Security SpecialistCommented:
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
 
lapuccaAuthor Commented:
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
 
Naitik GamitSoftware DeveloperCommented:
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
Kamal KhaleefaInformation Security SpecialistCommented:
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
 
lapuccaAuthor Commented:
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
 
Naitik GamitSoftware DeveloperCommented:
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
 
lapuccaAuthor Commented:
Thank you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now