views:

713

answers:

3

I have a gridview and I add some buttons programmatically to this grid. I have an edit and delete button right next to eachother and I simply want to put a space between them programmatically. Any idea how to do that? Here is the code to add the buttons.

For i As Integer = 0 To GridView1.Rows.Count - 1
            btnedit.ImageUrl = "\images\bttnEditMini.gif"
            btndelete.ToolTip = "Deletes the Current Record"
            btnedit.ToolTip = "Edits the Current Record"
            btndelete.ImageUrl = "\images\bttnDeleteMini.gif"
            GridView1.Rows(i).Cells(2).Controls.Add(btnview)
            GridView1.Rows(i).Cells(4).Controls.Add(btnedit)
            GridView1.Rows(i).Cells(4).Controls.Add(btndelete)
        Next
+4  A: 

Try this:

For i As Integer = 0 To GridView1.Rows.Count - 1
    btnedit.ImageUrl = "\images\bttnEditMini.gif"
    btndelete.ToolTip = "Deletes the Current Record"
    btnedit.ToolTip = "Edits the Current Record"
    btndelete.ImageUrl = "\images\bttnDeleteMini.gif"
    GridView1.Rows(i).Cells(2).Controls.Add(btnview)
    GridView1.Rows(i).Cells(4).Controls.Add(btnedit)
    GridView1.Rows(i).Cells(4).Controls.Add(new LiteralControl(" "))
    GridView1.Rows(i).Cells(4).Controls.Add(btndelete)
Next
Andrew Hare
Gaah!! I cannot get the editor to display the HTML entity " " The single space inside the LiteralControl constructor is supposed to be " ".
Andrew Hare
Close. It caused the buttons to sit on top of eachother.
Eric
Eric
Instead of adding a LiteralControl you could add an Image (ideally transparent) with width and height of 1...
wweicker
@Seanix: That would make for a very small space between the buttons :)
Andrew Hare
+1  A: 

add a Literal control between the edit and delete button (the text of the control should be

" " [Empty Space]

or

" "
Jon Erickson
A: 

I'd recommend creating a simple CssClass for your buttons that has the right and/or left margin set to the desired gap. That way you can add multiple buttons on the fly without worrying about having to insert "shims" with spaces or transparent gif files. It will also allow you to easily modify the gap down the road if you needs change.

Dillie-O