Last post Dec 12, 2016 05:36 AM by Eric Du
Dec 10, 2016 03:48 PM|kaiclassic|LINK
Let's suppose I use a Gridview to display data from one table (call it TableA). When editing a row, I want one set of columns to be editable. When editing another one, different set of columns to be editable. The rule to determine which column editable is
in another database table (call it TableB). Of course, the two tables have the same index (call it CustomerID).
Here is my idea on how to do this: Add the RowDataBound event handler. Use the CustomerID of selected row, do a database lookup to TableB. Then set each column (or actually asp:BoundField) to be read only.
Am I on the right track? Or the native asp:GridView does not support this requirement? Do I have to use any other type of data controls? Or I have to buy an existing product?
[Edit]: I have tried using RowDataBound, but turn the field that I need to change to TemplateField (with TextBox in edit mode and Lable in item mode),
no not working.
I even use the RowCreated and set the column, but no not working neither.
Dec 11, 2016 07:54 AM|kaiclassic|LINK
Turns out I have answered my own question!
I have joined the two table. The "Editable" column is from another table - call it Control table. This table indicates if each column of each row in the first table is editable. The example above shows Wally can change his own first name!
In my RowDataBound, I have the following to set the Enabled field of each cell:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim cellFirstNameReadOnly As TableCell
Dim cellLastNameReadOnly As TableCell
If e.Row.RowType = DataControlRowType.DataRow Then
cellFirstNameReadOnly = e.Row.Cells(3)
cellLastNameReadOnly = e.Row.Cells(5)
If cellFirstNameReadOnly.Text = "False" Then
e.Row.Cells(2).Enabled = False
If cellLastNameReadOnly.Text = "False" Then
e.Row.Cells(4).Enabled = False
Dec 12, 2016 05:36 AM|Eric Du|LINK
I'm glad to hear your problem has been solved, please mark your reply as answer, because it might help people who have the same trouble as you!