DataGrid WebServer Control - Dynamically change the edititemstyle
-
I am writing a ASP.NET application with a UI based on the DataGrid WebServer Control. The user is able to write back data do the system by clicking on the edit-button in the first column of the datagrid. However, the user is not always allowed to write back data in alls columns, this depends on his/hers priveleges. Example, lets say the datagrid have three columns plus the edit column: edit col1 col2 col3 And the active user only has permissions enough to edit col1 and col3. When this user press the edit button only the cells in col1 and col3 should display textboxes that allow the user to enter a value. How can this be implemented? I have understood that I should to it in the ItemCreated eventhandler. But I haven't figured out how do it exactly yet. Anyone who can help me? /Rickard
-
I am writing a ASP.NET application with a UI based on the DataGrid WebServer Control. The user is able to write back data do the system by clicking on the edit-button in the first column of the datagrid. However, the user is not always allowed to write back data in alls columns, this depends on his/hers priveleges. Example, lets say the datagrid have three columns plus the edit column: edit col1 col2 col3 And the active user only has permissions enough to edit col1 and col3. When this user press the edit button only the cells in col1 and col3 should display textboxes that allow the user to enter a value. How can this be implemented? I have understood that I should to it in the ItemCreated eventhandler. But I haven't figured out how do it exactly yet. Anyone who can help me? /Rickard
RickardB wrote: I have understood that I should to it in the ItemCreated eventhandler No,you should do it in EditItem event handler and set the EditItemIndex of datagrid to e.Item.ItemIndex and then rebind the grid to dataset.Also you should set EditItemTemplate tag in the HTML page of your aspx and set the edit controls that you want to be shown there,then for the problem of privilage,set the Visible attribute for each tag and for the value of it call the function in code-behind which check the permission and return boolean for the proper pemiission. For calling the function from code behind you should do something like this: Visible='< % # functionname(someparameter) % > ' but without any space. Mazy No sig. available now.
-
RickardB wrote: I have understood that I should to it in the ItemCreated eventhandler No,you should do it in EditItem event handler and set the EditItemIndex of datagrid to e.Item.ItemIndex and then rebind the grid to dataset.Also you should set EditItemTemplate tag in the HTML page of your aspx and set the edit controls that you want to be shown there,then for the problem of privilage,set the Visible attribute for each tag and for the value of it call the function in code-behind which check the permission and return boolean for the proper pemiission. For calling the function from code behind you should do something like this: Visible='< % # functionname(someparameter) % > ' but without any space. Mazy No sig. available now.
I am using autogenereted columns so I don't think your suggestion works. The amount and the types of the columns are generated in run time. The autogenerated editcolumns includes a textbox control by default, what I want to do it to set this textbox enabled property to false if the user doesn't has the permissions required to edit data in the specific column. Rickard Berglen, M.Sc.Eng.
-
I am writing a ASP.NET application with a UI based on the DataGrid WebServer Control. The user is able to write back data do the system by clicking on the edit-button in the first column of the datagrid. However, the user is not always allowed to write back data in alls columns, this depends on his/hers priveleges. Example, lets say the datagrid have three columns plus the edit column: edit col1 col2 col3 And the active user only has permissions enough to edit col1 and col3. When this user press the edit button only the cells in col1 and col3 should display textboxes that allow the user to enter a value. How can this be implemented? I have understood that I should to it in the ItemCreated eventhandler. But I haven't figured out how do it exactly yet. Anyone who can help me? /Rickard
Why not exclude the columns the user should not be editing from the datagrid completely using parameterized sql statements?
// Steve McLenithan
Cluelessnes:
There are no stupid questions, but there are a lot of inquisitive idiots. -
Why not exclude the columns the user should not be editing from the datagrid completely using parameterized sql statements?
// Steve McLenithan
Cluelessnes:
There are no stupid questions, but there are a lot of inquisitive idiots.First of all its not connected to a SQL source. The data source is a custom function that constructs the data by reading OPC Historical data from an Industrial Automation System. Second I want the user to be able to see the columns that his not allowed to edit while editing the other columns, to avoid confusion. Anyway, thanks for your reply. Rickard
-
First of all its not connected to a SQL source. The data source is a custom function that constructs the data by reading OPC Historical data from an Industrial Automation System. Second I want the user to be able to see the columns that his not allowed to edit while editing the other columns, to avoid confusion. Anyway, thanks for your reply. Rickard
Ok in that case perhaps you could try setting the fields you want to restrict (textboxes, dropdownmenus,etc) when in edit mode to ReadOnly based on their permission level?
// Steve McLenithan
Cluelessnes:
There are no stupid questions, but there are a lot of inquisitive idiots. -
Ok in that case perhaps you could try setting the fields you want to restrict (textboxes, dropdownmenus,etc) when in edit mode to ReadOnly based on their permission level?
// Steve McLenithan
Cluelessnes:
There are no stupid questions, but there are a lot of inquisitive idiots.Exactly, this is what I want to do. But how do I do it? Since I don't know the amount of columns in the datagrid until it is generated in design time my idea is to somehow modify the text boxes that appear when your press the "update" button in the ItemCreated Event handler. But for some reason I can't get hold of those textboxes. Rickard