Remove blank space in datagrid
-
Hello, We have created user control using data grid in VB.Net. In this datagrid we are dispalying for each row edit and delete icon. If user does not have access then we don't want to display edit & delete icon, but some blank space is coming in place of icons. We don't want this blank space if user does not have access for edit & delete. Can somebody give sample code how to remove that blank space.
Thanks & Regards, Kumar
-
Hello, We have created user control using data grid in VB.Net. In this datagrid we are dispalying for each row edit and delete icon. If user does not have access then we don't want to display edit & delete icon, but some blank space is coming in place of icons. We don't want this blank space if user does not have access for edit & delete. Can somebody give sample code how to remove that blank space.
Thanks & Regards, Kumar
Hide the Datagrid column instead of hiding the icons, Add the code below on Page_Load.
If IsUserHasAddDelEditAccess = False Then 'Hide Columns for Add, Edit and Delete 'Add Column DataGrid1.Columns(10).Visible = False 'Edit Column DataGrid1.Columns(11).Visible = False 'Delete Column DataGrid1.Columns(12).Visible = False End If
Regards, Mark -
Hello, We have created user control using data grid in VB.Net. In this datagrid we are dispalying for each row edit and delete icon. If user does not have access then we don't want to display edit & delete icon, but some blank space is coming in place of icons. We don't want this blank space if user does not have access for edit & delete. Can somebody give sample code how to remove that blank space.
Thanks & Regards, Kumar
Another Option for you. 1. Add an image and imagebutton to your datagrid add column 2. Set the image visibility to false. this image will represent a user have no access. 3. Override the DataGrid ItemDataBound Event. for your reference see the code below.
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound If IsUserHasAddDelEditAccess = False Then Dim imgbAdd As ImageButton = CType(e.Item.Cells(0).FindControl("imgButtonAdd"), ImageButton) imgbAdd.Visible = False Dim imgAddGrey As WebControls.Image = CType(e.Item.Cells(0).FindControl("imgAddGrey"), WebControls.Image) imgAddGrey.Visible = True ' Do the same thing with Edit and Delete End If End Sub
Regards, Mark -
Another Option for you. 1. Add an image and imagebutton to your datagrid add column 2. Set the image visibility to false. this image will represent a user have no access. 3. Override the DataGrid ItemDataBound Event. for your reference see the code below.
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound If IsUserHasAddDelEditAccess = False Then Dim imgbAdd As ImageButton = CType(e.Item.Cells(0).FindControl("imgButtonAdd"), ImageButton) imgbAdd.Visible = False Dim imgAddGrey As WebControls.Image = CType(e.Item.Cells(0).FindControl("imgAddGrey"), WebControls.Image) imgAddGrey.Visible = True ' Do the same thing with Edit and Delete End If End Sub
Regards, MarkThanks a lot. First one code is working for us.
Thanks & Regards, Kumar