[英]how to use GridViewUpdateEventArgs inside a property method VB.NET
I wanna show drop down list on the footer of my GridView. 我想在GridView的页脚上显示下拉列表。
aspx code:
<FooterTemplate>
<asp:DropDownList ID="ddSrc" runat="server">
</asp:DropDownList>
</FooterTemplate>
'VB Code
Protected Sub gvID_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DataItem IsNot Nothing Then
Dim ddSrc As DropDownList = DirectCast(e.Row.FindControl("ddSrc"), DropDownList)
If ddSrc IsNot Nothing Then
ddSrc.DataTextField = "Name"
ddSrc.DataValueField = "Id"
ddSrc.DataSource = GetData()
ddSrc.DataBind()
End If
End If
End If
End Sub
I have used above code behind code used to load my dropdown list but getting issue like "object reference not set to an instance of an object " over the line " ddSrc.DataTextField = "Name" " during runtime. 我在代码后面使用了上面的代码来加载我的下拉列表,但是在运行时“ ddSrc.DataTextField =”Name“ ”这一行上遇到 “对象引用没有设置为对象实例 ”的问题 。
I have edited my question to easy understand. 我编辑了我的问题以便于理解。
you need to load droupdown list on RowDataBound event of grid view 您需要在网格视图的RowDataBound事件上加载droupdown列表
Protected Sub gvID_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Footer Then
If e.Row.DataItem IsNot Nothing Then
Dim ddSrc As DropDownList = DirectCast(e.Row.FindControl("ddSrc"), DropDownList)
If ddSrc IsNot Nothing Then
ddSrc.DataTextField = "Name"
ddSrc.DataValueField = "Id"
ddSrc.DataSource = GetData()
ddSrc.DataBind()
End If
End If
End If
End Sub
Shot in the dark, but could it mean it requires a 'new' in the declaration? 在黑暗中拍摄,但这是否意味着它需要声明中的“新”?
Dim e As New GridViewUpdateEventArgs
If it hasnt been created yet, you wont be able to assign a variable to it. 如果尚未创建,您将无法为其分配变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.