Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DetailsView Databound event
 

DetailsView Databound event

Hi all,

Should need some help on this :

I have a Detailsview "ProductDetails"where some labels have custom formatting, i.e.:

<asp:Label ID="absoluteMargin" runat="server" OnDataBinding="ProductDetails_DataBound"></asp:Label>

The formatting occurs when the data is bound. This is only used in the Itemtemplate created for the productinfo. The InsertTemplate should do no formatting because there isno data (yet). But it seems that de ProductsDetails Itemtemplate also reacts on the insert command.

I get the exception: "Object reference not set to an intance of an object" for the ProductDetails.DataItem.

The Productsdetails_Databound() should not fire when going to InsertTemplate. What should be the workarround for this? I understand that a NullException fireswhen there is no data to be bound.

I short : how can I make the Productsdetails_Databound() works only for the ItemTemplate of Productsdetails and fires no exceptions :-)

Protected Sub ProductDetails_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProductDetails.DataBound

Try

Dim product As MFDatabaseDAL.PRODUCTSRow = CType(CType(ProductDetails.DataItem, System.Data.DataRowView).Row, MFDatabaseDAL.PRODUCTSRow)

Dim absMargin As Label = CType(ProductDetails.FindControl("absoluteMargin"), Label) '

'Do Some formatting

Catch ex As Exception

'do something

End Try

End Sub

Olivier .NET  Tuesday, October 24, 2006 1:45 PM
Even I am having a same situation. if u get any answer or solved it please post it here too!
thanks
schauhan  Thursday, July 16, 2009 2:40 PM
did u get any way to solve this
  • Proposed As Answer bylegal101205~ Friday, September 04, 2009 10:06 AM
  •  
schauhan  Thursday, July 16, 2009 2:42 PM

        protected void DetailsView1_DataBound(object sender, EventArgs e)
        {
            DetailsView that = (DetailsView)sender;
            if (that.CurrentMode == DetailsViewMode.ReadOnly&& that.Rows.Count > 0)
            {
                TableCell header;
                TableCell dataCell;
                foreach (DetailsViewRow dvr in that.Rows)
                {
                    header = dvr.Cells[0];
                    dataCell = dvr.Cells[1];
                }
            }
        }

legal101205~  Friday, September 04, 2009 10:09 AM

You can use google to search for other answers

Custom Search

More Threads

• how to set default value for a textbox?
• ComboBox and TextBox in DataGridView
• C#+COM+Threads: working with Word/Excel using BackGroundWorker problem
• Binding Navigator Desapiring
• i broke something and i don't know what!
• .NET and MS Access Support
• Data exporting to Excel .. Error
• Finding Dataset Template
• How to connect dataGridView with listBoxes
• DataGridView.DisplayIndex unexpected behavior when bound to List<>