Setting DataGrid Event Handler at Runtime

Results 1 to 2 of 2

Thread: Setting DataGrid Event Handler at Runtime

  1. #1
    Join Date
    Dec 1969

    Default Setting DataGrid Event Handler at Runtime

    Hi-<BR><BR>I&#039;m creating a web app that displays multiple tables returned from a SQL stored procedure. Because I don&#039;t know how many tables might be returned, and I want each table to be in its own datagrid, I create the datagrids at runtime. What I&#039;m having problems with is when I try to set the OnEditCommand attribute to the name of the function I&#039;m setting up to handle when the edit button is clicked. I get the error "System.Web.UI.WebControls.DataGrid.Protected Overridable Overloads Sub OnEditCommand(e as System.Web.UI.WebControls.DataGridCommandEventArgs ) is not accessible in this context because it is &#039;Protected&#039;" I&#039;m not sure what I&#039;m doing wrong. Any help would be appreciated!<BR>Here&#039;s the code:<BR><BR>Dim clmEditColumn As New EditCommandColumn()<BR> Dim blnStatus As Boolean = False<BR> Dim i As Integer<BR> Dim j As Integer<BR> Dim strSecurityLevel As String = "HIGH"<BR><BR> blnEventLogStatus = clsLogging.InitializeEventLog(evlEventLog)<BR><BR> Dim param1 As New SqlParameter("@SelectedSite", SqlDbType.VarChar, 500, ParameterDirection.Input, False, 0, 0, "", DataRowVersion.Default, lstSiteNames.SelectedItem.Value)<BR> blnStatus = clsDatabase.RunSQLProcedure(SQLPROCEDURE_GET_SITE_ DATA, dtsQueryResults, strSQLError, param1)<BR><BR> If blnStatus Then<BR> For i = 0 To (dtsQueryResults.Tables.Count - 1)<BR> Dim dgrDataGrid As New DataGrid()<BR><BR> blnStatus = clsFormatting.FormatDataGrid(dgrDataGrid)<BR><BR> With dgrDataGrid<BR> .ID = "dgrDataGrid" & i<BR> .AutoGenerateColumns = False<BR> .DataSource = dtsQueryResults.Tables(i)<BR> .OnEditCommand = "dgrDataGrid_EditCommand"<BR><BR> For j = 1 To (dtsQueryResults.Tables(i).Columns.Count - 1)<BR><BR> Dim clmBoundColumn As New BoundColumn()<BR><BR> With clmBoundColumn<BR> .DataField = dtsQueryResults.Tables(i).Columns(j).ColumnName<BR > .HeaderText = dtsQueryResults.Tables(i).Columns(j).ColumnName<BR ><BR> End With<BR><BR> .Columns.Add(clmBoundColumn)<BR><BR> Next<BR><BR> If strSecurityLevel = "HIGH" Then<BR> With clmEditColumn<BR> .ButtonType = ButtonColumnType.LinkButton<BR> .EditText = "EDIT"<BR> .UpdateText = "UPDATE"<BR> .CancelText = "CANCEL"<BR><BR> End With<BR><BR> .EditItemIndex = 0<BR> .Columns.Add(clmEditColumn)<BR> .EditItemIndex = -1<BR><BR> End If<BR><BR> .DataBind()<BR><BR> End With<BR><BR> Panel.Controls.Add(New LiteralControl("&#060;P&#062;"))<BR> Panel.Controls.Add(dgrDataGrid)<BR> Panel.Controls.Add(New LiteralControl("&#060;/P&#062;"))<BR><BR> dgrDataGrid.Dispose()<BR><BR> Next<BR><BR> Else<BR> lblError.Text = strSQLError<BR> If blnEventLogStatus Then<BR> blnStatus = clsLogging.WriteToEventLog(evlEventLog, strSQLError)<BR><BR> End If<BR><BR> End If<BR><BR> blnStatus = clsLogging.CloseEventLog(evlEventLog)<BR>

  2. #2

    Default RE: Setting DataGrid Event Handler at Runtime

    I&#039;m not sure you can wire it up like that, even though it is a text property in the html.<BR><BR>I got it to call this<BR> public void dgrDataGrid_EditCommand(object sender,DataGridCommandEventArgs e)<BR> {<BR> Response.Write (((DataGrid)sender).ID);<BR> <BR> }<BR>using this<BR><BR> DataGrid dgrDataGrid = new DataGrid();<BR> dgrDataGrid.ID="DG_1";<BR> dgrDataGrid.EditCommand += new DataGridCommandEventHandler(dgrDataGrid_EditComman d );<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts