Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Pete Mahoney #1
Postback for DataGrid Columns Added in Code Behind not firing.
I am trying to build a web custom control that displays a datagrid, so
first off I have no designer where I can drag and drop a datagrid and
then set properties from the user interface. I have to do everything
from the code behind. Most of the code follows below.
The problem is after I create my datagrid from the code behind and add
ButtonColumn's to the datagrid the items in those ButtonColumn's
should do a post back after being pressed. No such postback is ever
called from these ButtonColumn's and thus no server side code for
Edit, Update or Delete buttons can ever be called.
How can I get my datagrid ButtonColumn or EditCommandColumn to
properly do post back when they are created from the code behind?
Public Sub BuildDG()
dgDisplayFiles.ID = "dgDisplayFiles"
dgDisplayFiles.AutoGenerateColumns = False
dgDisplayFiles.DataKeyField = "FullName"
dgDisplayFiles.HeaderStyle.CssClass =
ViewState("HeaderStyle-CssClass")
dgDisplayFiles.ItemStyle.CssClass = ViewState("ItemStyle-CssClass")
Dim deleteColumn As New System.Web.UI.WebControls.ButtonColumn
deleteColumn.Text = "<img src='/images/common/delete.gif' border=0>"
deleteColumn.CommandName = "Delete"
deleteColumn.ButtonType = WebControls.ButtonColumnType.LinkButton
Dim renameColumn As New System.Web.UI.WebControls.EditCommandColumn
renameColumn.EditText = "<img src='/images/common/edit.gif' border=0>"
renameColumn.ButtonType = WebControls.ButtonColumnType.LinkButton
Dim previewColumn As New System.Web.UI.WebControls.HyperLinkColumn
previewColumn.Text = "<img src='/images/common/preview.gif' border=0>"
previewColumn.Target = "_blank"
Dim nameColumn As New System.Web.UI.WebControls.BoundColumn
nameColumn.DataField = "Name"
nameColumn.HeaderText = "Name"
Dim lastUpdatedColumn As New System.Web.UI.WebControls.BoundColumn
lastUpdatedColumn.DataField = "LastWriteTime"
lastUpdatedColumn.HeaderText = "Last Modified"
dgDisplayFiles.Columns.Add(deleteColumn)
dgDisplayFiles.Columns.Add(renameColumn)
dgDisplayFiles.Columns.Add(previewColumn)
dgDisplayFiles.Columns.Add(nameColumn)
dgDisplayFiles.Columns.Add(lastUpdatedColumn)
End Sub
Public Sub BindFiles()
Dim dir As New
DirectoryInfo(ViewState("strDirectoryLocation"))
If dir.Exists Then
dgDisplayFiles.DataSource =
dir.GetFiles(ViewState("strTypeOfFile"))
dgDisplayFiles.DataBind()
If dgDisplayFiles.Items.Count = 0 Then
dgDisplayFiles.Visible = False
Else
dgDisplayFiles.Visible = True
End If
End If
End Sub
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
dgDisplayFiles = New System.Web.UI.WebControls.DataGrid
BuildDG()
BindFiles()
dgDisplayFiles.RenderControl(output)
End Sub
Pete Mahoney Guest
-
Help with Dynamic Columns in Datagrid and Postback
Hi, I'm having problems retaining my dynamic columns during postbacks. I've read that if you create dynamic columns at runtime, you have to add... -
Autogenerated Datagrid columns rebinding problem on postback
Just to give a brief background what I'm trying to do, is I have a DataGrid with 2 static columns, and the rest are autogenerated (which have... -
Sort not firing PostBack event using Dynamic Columns
I am having a problem with the DataGrid control and sorting, and have found it's realted to if you use dynamic columns or not. If I set the columns... -
Keeping DataGrid Columns through Postback
I am doing the exact same thing you are requesting. Here is what you do: 1. You must wire-up a method to the eventhandler of the grid called... -
Datagrid Dynamic Columns Postback and SelectedIndexChanged problems
All, I have a datagrid that has a few design time columns (two buttons - one for select and one for delete) and the programatically I add... -
Raghavendra T V #2
Re: Postback for DataGrid Columns Added in Code Behind not firing.
Hi Pete,
I guess the delegate ( events) in the initialize() are missing.
Check wether all delegates for datagrid are present in the initialize ().
VS.NET sometimes swallows this events ( i think its a bug )
Hope this helps you.
Thanks
Raghavendra
"Pete Mahoney" <landerud.pete@students.uwlax.edu> wrote in message
news:189dfa06.0408301049.4e699080@posting.google.c om...> I am trying to build a web custom control that displays a datagrid, so
> first off I have no designer where I can drag and drop a datagrid and
> then set properties from the user interface. I have to do everything
> from the code behind. Most of the code follows below.
>
> The problem is after I create my datagrid from the code behind and add
> ButtonColumn's to the datagrid the items in those ButtonColumn's
> should do a post back after being pressed. No such postback is ever
> called from these ButtonColumn's and thus no server side code for
> Edit, Update or Delete buttons can ever be called.
>
> How can I get my datagrid ButtonColumn or EditCommandColumn to
> properly do post back when they are created from the code behind?
>
> Public Sub BuildDG()
> dgDisplayFiles.ID = "dgDisplayFiles"
> dgDisplayFiles.AutoGenerateColumns = False
>
> dgDisplayFiles.DataKeyField = "FullName"
> dgDisplayFiles.HeaderStyle.CssClass =
> ViewState("HeaderStyle-CssClass")
> dgDisplayFiles.ItemStyle.CssClass = ViewState("ItemStyle-CssClass")
>
> Dim deleteColumn As New System.Web.UI.WebControls.ButtonColumn
> deleteColumn.Text = "<img src='/images/common/delete.gif' border=0>"
> deleteColumn.CommandName = "Delete"
> deleteColumn.ButtonType = WebControls.ButtonColumnType.LinkButton
>
> Dim renameColumn As New System.Web.UI.WebControls.EditCommandColumn
> renameColumn.EditText = "<img src='/images/common/edit.gif' border=0>"
> renameColumn.ButtonType = WebControls.ButtonColumnType.LinkButton
>
> Dim previewColumn As New System.Web.UI.WebControls.HyperLinkColumn
> previewColumn.Text = "<img src='/images/common/preview.gif' border=0>"
> previewColumn.Target = "_blank"
>
> Dim nameColumn As New System.Web.UI.WebControls.BoundColumn
> nameColumn.DataField = "Name"
> nameColumn.HeaderText = "Name"
>
> Dim lastUpdatedColumn As New System.Web.UI.WebControls.BoundColumn
> lastUpdatedColumn.DataField = "LastWriteTime"
> lastUpdatedColumn.HeaderText = "Last Modified"
>
> dgDisplayFiles.Columns.Add(deleteColumn)
> dgDisplayFiles.Columns.Add(renameColumn)
> dgDisplayFiles.Columns.Add(previewColumn)
> dgDisplayFiles.Columns.Add(nameColumn)
> dgDisplayFiles.Columns.Add(lastUpdatedColumn)
> End Sub
>
> Public Sub BindFiles()
> Dim dir As New
> DirectoryInfo(ViewState("strDirectoryLocation"))
> If dir.Exists Then
> dgDisplayFiles.DataSource =
> dir.GetFiles(ViewState("strTypeOfFile"))
> dgDisplayFiles.DataBind()
> If dgDisplayFiles.Items.Count = 0 Then
> dgDisplayFiles.Visible = False
> Else
> dgDisplayFiles.Visible = True
> End If
> End If
> End Sub
>
> Protected Overrides Sub Render(ByVal output As
> System.Web.UI.HtmlTextWriter)
> dgDisplayFiles = New System.Web.UI.WebControls.DataGrid
>
> BuildDG()
>
> BindFiles()
>
> dgDisplayFiles.RenderControl(output)
> End Sub
Raghavendra T V Guest



Reply With Quote

