Yes! My mistake! Now it works fine! Thanks a lot!! ^_^
--- Rajendra Appalla <[EMAIL PROTECTED]> wrote: > You said you were populating the columns again in > postback too?? > I don't see you doing that?? > > You have to add columns to the datagrid in the > postback too in the > Page_Load. > I see you restricting for Not Is Post Back in the > page_load. You have > to load the columns in the page_load no matter it is > postback or not. > > And when you call BindGrid() at the end of edit and > delete events, you > should not add the columns. So you should have a > flag which you pass to > BindGrid(bool blnColumnsAdd) which you set to true > in page_load for both > postback and not postback and you set it to false, > at the end of the > events where again you call BindGrid(). > > Rajendra. > > -----Original Message----- > From: Psychomaniac > [mailto:[EMAIL PROTECTED] > Sent: Thursday, September 23, 2004 11:19 AM > To: [EMAIL PROTECTED] > Subject: RE: [AspNetAnyQuestionIsOk] Dynamic > Datagrids > > Thanks for the quick reply Rajendra, here's my code: > in my aspx I have: > > <ASP:DATAGRID id="DisplayDataGrid" runat="server" > OnDeleteCommand="DisplayDataGrid_Delete" > DataKeyField="id" > HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" > Font-Name="Verdana" CellPadding="3" > BorderColor="Black" > BackColor="#CCCCFF" Width="800px" > OnUpdateCommand="DisplayDataGrid_Update" > OnCancelCommand="DisplayDataGrid_Cancel" > OnEditCommand="DisplayDataGrid_Edit" > OnItemDataBound="DisplayDataGrid_ItemDataBound" > AutoGenerateColumns="False" > Font-Names="Verdana" BorderStyle="None"> > <HeaderStyle BackColor="#AAAADD"></HeaderStyle> > </ASP:DATAGRID> > > In my aspx.vb: > > Private Sub Page_Load(ByVal sender As System.Object, > ByVal e As System.EventArgs) Handles MyBase.Load > sqlconn = New > SqlConnection(Application("SQLConnStr")) > > If Not (IsPostBack) Then > BindGrid() > End If > End Sub > > Sub DisplayDataGrid_Edit(ByVal Sender As Object, > ByVal > E As DataGridCommandEventArgs) Handles > DisplayDataGrid.EditCommand > DisplayDataGrid.EditItemIndex = > CInt(E.Item.ItemIndex) > BindGrid() > End Sub > > Sub DisplayDataGrid_Cancel(ByVal Sender As Object, > ByVal E As DataGridCommandEventArgs) Handles > DisplayDataGrid.CancelCommand > DisplayDataGrid.EditItemIndex = -1 > BindGrid() > End Sub > > Sub DisplayDataGrid_Update(ByVal Sender As Object, > ByVal E As DataGridCommandEventArgs) Handles > DisplayDataGrid.UpdateCommand > 'Some Update codes > BindGrid() > End Sub > > Sub DisplayDataGrid_Delete(ByVal Sender As Object, > ByVal E As DataGridCommandEventArgs) Handles > DisplayDataGrid.DeleteCommand > Dim sqlcmd As SqlCommand > Dim DeleteCmd As String = "DELETE from tblMovies > where > ID = @Id" > > sqlcmd = New SqlCommand(DeleteCmd, sqlconn) > sqlcmd.Parameters.Add(New SqlParameter("@Id", > SqlDbType.Int, 4)) > sqlcmd.Parameters("@Id").Value = > DisplayDataGrid.DataKeys(CInt(E.Item.ItemIndex)) > > sqlcmd.Connection.Open() > > Try > sqlcmd.ExecuteNonQuery() > Catch Exc As SqlException > > End Try > > sqlcmd.Connection.Close() > > BindGrid() > End Sub > > Sub InitGrid() > Dim DataSetObj As New Data.DataSet > Dim sqlconn As New > SqlClient.SqlConnection(Application("SQLConnStr")) > Dim strSQL As String > Dim iCtr As Integer > > Try > Dim btnColumn As New ButtonColumn > btnColumn.HeaderImageUrl = > "images\button_drop.gif" > btnColumn.ButtonType = > ButtonColumnType.LinkButton > btnColumn.Text = "X" > btnColumn.CommandName = "Delete" > DisplayDataGrid.Columns.Add(btnColumn) > > 'Check for Authentication, then set the > visibility > for Delete & Edit Columns: > 'DisplayDataGrid.Columns(0).Visible = False > > Dim editCol As New EditCommandColumn > editCol.HeaderText = "Edit" > editCol.ButtonType = ButtonColumnType.LinkButton > editCol.UpdateText = "Update" > editCol.EditText = "Edit" > editCol.CancelText = "Cancel" > DisplayDataGrid.Columns.Add(editCol) > > AddHandler DisplayDataGrid.DeleteCommand, New > DataGridCommandEventHandler(AddressOf > DisplayDataGrid_Delete) > AddHandler DisplayDataGrid.EditCommand, New > DataGridCommandEventHandler(AddressOf > DisplayDataGrid_Edit) > AddHandler DisplayDataGrid.UpdateCommand, New > DataGridCommandEventHandler(AddressOf > DisplayDataGrid_Update) > AddHandler DisplayDataGrid.CancelCommand, New > DataGridCommandEventHandler(AddressOf > DisplayDataGrid_Cancel) > > strSQL = "SELECT * FROM GUI_tblDisplay WHERE > Groups = 'Edit' ORDER BY DisplayOrder" > sqlconn.Open() > Dim sqlDataSet As New > SqlClient.SqlDataAdapter(strSQL, sqlconn) > sqlDataSet.Fill(DataSetObj, "table") > > For iCtr = 0 To > DataSetObj.Tables("table").Rows.Count - 1 > Dim tc As New TemplateColumn > tc.ItemTemplate = New > clsDGItemTemplate(DataSetObj.Tables("table").Rows(iCtr).Item("FieldName" > )) > tc.HeaderText = > CStr(DataSetObj.Tables("table").Rows(iCtr).Item("DisplayName")) > 'tc.HeaderStyle.Width = > System.Web.UI.WebControls.Unit.Pixel(200) > tc.EditItemTemplate = New > clsDGEditItemTemplate(DataSetObj.Tables("table").Rows(iCtr).Item("FieldN > ame")) > DisplayDataGrid.Columns.Add(tc) > Next > Catch exp As Exception > Response.Write("Error in initializing datagrid! > edit.InitGrid() " & exp.ToString) > Catch sql_exp As SqlClient.SqlException > Response.Write("Error in initializing datagrid! > edit.InitGrid() " & sql_exp.ToString) > Finally > Try > sqlconn.Close() > DataSetObj.Dispose() > sqlconn = Nothing > DataSetObj = Nothing > Catch exp As Exception > > End Try > End Try > End Sub > > Sub BindGrid() > InitGrid() > > Dim DS As DataSet > Dim MyCommand As SqlDataAdapter > === message truncated === __________________________________ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail ------------------------ Yahoo! Groups Sponsor --------------------~--> Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar. Now with Pop-Up Blocker. Get it for free! http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
