当前位置:  开发笔记 > 后端 > 正文

Repeater Button CommandArgument是空字符串

如何解决《RepeaterButtonCommandArgument是空字符串》经验,为你挑选了1个好方法。

用这个失去理智.即使命令设置已设置,我的按钮也会获得空字符串的命令参数.我已经验证它在调试模式下被设置为正确的ID,但是当我稍后在转发器ItemCommand事件中访问此命令参数时,commandarguments是空字符串.我不明白为什么.我最终得到一个sq外键异常,因为它从空字符串值插入ID为0.关于将重置它的转发器按钮没有其他代码.

中继器:


    
        
        
        
    

代码背后:

    Protected Sub repeaterAddresses_ItemCreated(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles repeaterAddresses.ItemCreated
        If Not IsNothing(DirectCast(e.Item.DataItem, DataRowView)) Then
            If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
                Dim addressControl As Address = DirectCast(e.Item.FindControl("AddressControl"), Address)
                addressControl.AddressID = CInt(DirectCast(e.Item.DataItem, DataRowView)("Address_ID").ToString())
                Dim btnBilling As Button = DirectCast(e.Item.FindControl("btnMarkAsBilling"), Button)
                btnBilling.CommandArgument = CInt(DirectCast(e.Item.DataItem, DataRowView)("Address_ID").ToString())
                Dim btnPhysical As Button = DirectCast(e.Item.FindControl("btnMarkAsPhysical"), Button)
                btnPhysical.CommandArgument = CInt(DirectCast(e.Item.DataItem, DataRowView)("Address_ID").ToString())
            End If
        End If
    End Sub
   Protected Sub repeaterAddress_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs) Handles repeaterAddresses.ItemCommand
        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Trustaff_ESig2").ConnectionString)
        Dim button As Button = CType(e.CommandSource, Button)

        Select Case e.CommandName
            Case "Billing"
                Dim cmdBillingAddress As New SqlCommand("[SP_Facility_UpdateBillingAddress]", conn)
                With cmdBillingAddress
                    .CommandType = CommandType.StoredProcedure
                    .Parameters.Add(New SqlParameter("@Facility_ID", DbType.Int32)).Value = sqlFacilityAddresses.SelectParameters("Facility_ID").DefaultValue
                    .Parameters.Add(New SqlParameter("@BillingAddress_ID", DbType.Int32)).Value = e.CommandArgument
                End With
                conn.Open()
                cmdBillingAddress.ExecuteNonQuery()
                conn.Close()
            Case "Physical"
                Dim cmdPhysicalAddress As New SqlCommand("[SP_Facility_UpdatePhysicalAddress]", conn)
                With cmdPhysicalAddress
                    .CommandType = CommandType.StoredProcedure
                    .Parameters.Add(New SqlParameter("@Facility_ID", DbType.Int32)).Value = sqlFacilityAddresses.SelectParameters("Facility_ID").DefaultValue
                    .Parameters.Add(New SqlParameter("@PhysicalAddress_ID", DbType.Int32)).Value = e.CommandArgument
                End With
                conn.Open()
                cmdPhysicalAddress.ExecuteNonQuery()
                conn.Close()
        End Select
        PopulateBillingPhysicalAddresses(sqlFacilityAddresses.SelectParameters("Facility_ID").DefaultValue)
    End Sub

Kyle Trauber.. 11

试试这个:


请注意属性值周围的单引号.如果它们是双引号,ASP.NET将不会执行服务器端数据绑定代码.您需要CommandArgument从后面的代码中删除分配.

Address_ID 将需要是您正在与转发器数据绑定的对象的属性.



1> Kyle Trauber..:

试试这个:


请注意属性值周围的单引号.如果它们是双引号,ASP.NET将不会执行服务器端数据绑定代码.您需要CommandArgument从后面的代码中删除分配.

Address_ID 将需要是您正在与转发器数据绑定的对象的属性.

推荐阅读
135369一生真爱_890
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有