wsyeager Posted August 30, 2003 Posted August 30, 2003 I would like to dynamically create a button in the "footer" section of a datagrid. Once this button is created, I would like to wire up an existing event (by another button) to this new dynamically created button. I have the following code in my Item_DAtabound event of the datagrid. If e.Item.ItemType = ListItemType.Footer Then Dim btnSave2 As System.Web.UI.WebControls.Button = New System.Web.UI.WebControls.Button e.Item.Cells(10).Controls.Add(btnSave2) btnSave2.Width.Pixel(105) btnSave2.Height.Pixel(32) btnSave2.Text = "Save" AddHandler btnSave2.Click, AddressOf btnSave_Click End If The button gets displayed, but after it's clicked, it disappears. In addition, it doesn't go into the btnSave_Click event (below): Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click . . . End sub What do I need to do in order to get this to work??? Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
bhatti81 Posted August 30, 2003 Posted August 30, 2003 this might solve ur problem http://www.datagridcolumnstyles.net/examples.asp check out the examples in here. cheers, Hayee Quote
wsyeager Posted August 30, 2003 Author Posted August 30, 2003 thanks, but unfortunately, that's not what i was looking for..... Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
*Gurus* Derek Stone Posted August 30, 2003 *Gurus* Posted August 30, 2003 Creating controls dynamically is not a good idea. If at all possible create the button along with your other controls and set its Visible property to true when it is needed to be displayed. Quote Posting Guidelines
wsyeager Posted August 30, 2003 Author Posted August 30, 2003 Dreek, I already have a save button on my form at the top of my grid. There are always going to be 48 rows on one page. I wanted to place another "SAve" button inside the footer of the grid dynamcially tht will execute the same code as the first "Save button so the user won't have to scroll up to do the save. Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
*Gurus* Derek Stone Posted August 31, 2003 *Gurus* Posted August 31, 2003 So put the button there... I'm not seeing why it has to be dynamic. Quote Posting Guidelines
wsyeager Posted September 1, 2003 Author Posted September 1, 2003 Since I want to place the button inside the footer of the datagrid, that's why it needs to be dynamic in the "databound" event of the datagrid. Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
*Gurus* Derek Stone Posted September 1, 2003 *Gurus* Posted September 1, 2003 So you want it inside the block of HTML that is rendered by the DataGrid? Forgive me if I'm wrong, but I don't believe you can do that without overriding one of the control's Render methods, which with a DataGrid is quite a bit of work. However you can display a button below the DataGrid using the DataBinding event: Private Sub DataGrid1_DataBinding(ByVal sender As Object, ByVal e As EventArgs) Handles DataGrid1.DataBinding SaveButton.Visible = True End Sub 'DataGrid1_DataBinding Quote Posting Guidelines
wsyeager Posted September 2, 2003 Author Posted September 2, 2003 dynamically create a button Derek, I was finally able to do it via the following code in the ItemCreated method. <code> If e.Item.ItemType = ListItemType.Footer Then btnSave2 = New System.Web.UI.WebControls.Button e.Item.Cells(10).Controls.Add(btnSave2) btnSave2.Width.Pixel(105) btnSave2.Height.Pixel(32) btnSave2.Text = "Save" AddHandler btnSave2.Click, AddressOf btnSave_Click End If </code> The dynamically created button responds perfectly to the btnSave_Click event when pressed....... Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
*Gurus* Derek Stone Posted September 3, 2003 *Gurus* Posted September 3, 2003 Glad to see you got it. I honestly didn't have a damn clue as to exactly what you wanted. Oh well. :) Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.