本文介绍了Gridview_RowDataBound中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
This is my gridview row bound code
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lcl_date As String = "d-MMM-yyyy"
If Session("lcl_date") IsNot Nothing Then
lcl_date = Session("lcl_date")
End If
Dim podate As DateTime = DataBinder.Eval(e.Row.DataItem, "podate")
Dim lbl5 As Label = CType(e.Row.FindControl("Label5"), Label)
Dim txpodate As TextBox = CType(e.Row.FindControl("txt_podate"), TextBox)
lbl5.Text = podate.ToString(lcl_date)
txpodate.text = podate.ToString(lcl_date)
End If
End Sub
It was working fine if i do not add
Dim txtpodate as textbox and txtpodate.text
and corresponding asp.net code is as
<asp:TemplateField HeaderText="PO Date">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("podate") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_podate" runat="server" Text='<%# Bind("podate") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
but after adding this line in the gridview row databound, it displaying error as Object reference not set to instance of the object
推荐答案
If ((e.Row.RowState & DataControlRowState.Edit)) Then
Dim txpodate As TextBox = CType(e.Row.FindControl("txt_podate"), TextBox)
Response.Write(TextBox1.Text)
End If
这篇关于Gridview_RowDataBound中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!