Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Edit Command to cause vertical expansion 2

Status
Not open for further replies.

lanm

Programmer
Jul 7, 2005
244
US
I have a datagrid that has about 10 fields in it. The font size is a bit small, and when the user edits a row, it's a bit tough with the sizing....especially with the dropdownlist have field concatenation upon editing.

We'd like to implement a datagrid that upon the Edit command, it expands vertically. So, instead of one row with all the fields from left to right, I might be able to have the columsn stack upon each other almost like five rows with two columns per row, or two rows with 5 columns. This way I can make the font size much larger and easier for the users to read.

I know there are custom controls out there I've found in the past, but of course....can't find them with google searches. I don't mind trying to create my own custom control either...this is almost always the best way to learn. I just don't know how to change the grid row so all the fields change "Y" location. A little point in the right direction is appreciated.

Thanks!
 
This may help. It is routine that you put in the ItemDataBound event of the datagrid:

I lets you wrap your datagrid similar to what you are describing.
I have not tested this with an editable grid so you have to tweak it some.


Code:
Private Sub datagrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles datagrid1.ItemDataBound
        WrapDataGrid(sender, e, 5)
    End Sub

Code:
Public Sub WrapDataGrid(ByRef sender As Object, ByRef e As System.Web.UI.WebControls.DataGridItemEventArgs, ByVal WrapAfterCellNumber As Integer)
        If e.Item.Cells.Count > WrapAfterCellNumber Then
            Dim colspan = e.Item.Cells.Count - (e.Item.Cells.Count - WrapAfterCellNumber) - 1
            Dim lit As New Literal
            Dim css As String
            Dim style As String
            Dim dg As DataGrid = sender

            If e.Item.ItemType = ListItemType.Item Then
                css = dg.ItemStyle.CssClass
                style = dg.ItemStyle.ToString
            ElseIf e.Item.ItemType = ListItemType.AlternatingItem Then
                css = dg.AlternatingItemStyle.CssClass
                style = dg.AlternatingItemStyle.ToString
            Else
                css = dg.HeaderStyle.CssClass
                style = dg.HeaderStyle.ToString
            End If

            lit.Text = "</td></tr><tr style=""" & style & """ class=""" & css & """ ><td>&nbsp;"
            e.Item.Cells(WrapAfterCellNumber - 1).Controls.AddAt(e.Item.Cells(WrapAfterCellNumber - 1).Controls.Count, lit)
            e.Item.Cells(e.Item.Cells.Count - 1).ColumnSpan = colspan
        End If
    End Sub
 
Thanks TRome!

I'll try it out and let you know!
 
Excellent idea RTomes!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Couldn't you just set up the EditItemTemplate of 1 column to show all of the editable info (vertically) and then hide the rest of the columns until finished editing? If that's what you said RTomes, sorry, I don't understand VB very well.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top