Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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???

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Posted
thanks, but unfortunately, that's not what i was looking for.....

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Posted
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.

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Posted
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.

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

  • *Gurus*
Posted

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

Posted

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.......

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...