SPGridView – > RowDataBound Event

In MOSS you can use some of the included Controls for your own purpose. As example the GridView –> SPGridView.

For a good explanation look here –> http://www.sharepointblogs.com/wirkus/archive/2008/08/21/how-to-professionelle-datenanzeige-mit-dem-control-spgridview.aspx [GERMAN]

However some features from the big brother – the ASP.Net Gridview – are not implemented on the SPGridview. For example the DataFormat Property.

So you have to rebuild this on your own. This is done with the RowDataBound Event.

But there is a ugly bug (or is it even a feature…?). If you want to get the current Text of a row with “e.Rows.Cells[index[.text” it gives you nothing back. But you can write in this property and is used……

For a workaround convert the row into DataRowView Object. See example (you have to adopt it for your use….)

void spg_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                    DateTime date;
                    DataRowView rowView = ((DataRowView)(e.Row.DataItem));
                    if (DateTime.TryParse(rowView.Row.ItemArray[index].ToString(), out date))
                    {
                        e.Row.Cells[index].Text = rowView.Row.ItemArray[index].ToString() + " / " + date.ToString("dd.MM.yyyy");

                    }                  
                }
            }

        }

Found the solution here:http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/0ab222fa-e26f-49f0-b3ef-ed6afeadfaa5

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s