网格视图行数据绑定不响应 [英] grid view row databound not response

查看:82
本文介绍了网格视图行数据绑定不响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview控件中遇到行数据绑定问题?我在gridview中为imagebutton(add)添加了属性.ADD按钮正确响应,但是其他imagebutton(例如Edit,DEl)也响应相同的功能!这是我的问题!

i got issues for row databound in gridview controll?i add attributes for imagebutton(add) in gridview .ADD button correctly response, but other imagebutton like Edit,DEl also response same function! it is my problem!

If e.Row.RowType = DataControlRowType.DataRow Then
                
                Dim ADD_img As String = DirectCast(e.Row.FindControl("Add"), ImageButton).CommandName.ToString
                
 Dim del As String = DirectCast(e.Row.FindControl("imgdel"),ImageButton).CommandName.ToString
                
If Not Add_img Is Nothing Then
   Add_img = Add_img & "." & Session.Item("ID")
     e.Row.Attributes.Add("OnClick", "javascript:return openph(" & Edid_img & ")")           
end if     

                    If Not Del_img = "" is nothing Then

                    e.Row.Attributes.remove("OnClick")
                End If

推荐答案

查看此博客
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx [
check this blog
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx[^]
--NDK


您正在将JavaScript添加到整个Row中,而不是添加到单个ImageButton中.
You''re adding the javascript to the entire Row, not to the single ImageButton.
e.Row.Attributes.Add


因此,我认为,javascript函数将为整个行中的每个按钮和链接触发.
尝试将ADD_img强制转换为ImageButton(而不是字符串).然后


So, I think, the javascript function will trigger for every button and link in the entire row.
Try to cast ADD_img to a ImageButton (and not to a String). Then

ADD_img.Attributes.Add("OnClick", "javascript:return openph(" & Edid_img & ")")


抱歉,我使用C#编写代码,但应该相同.
让我知道!


Sorry, I code in C# but should be the same.
Let me know!


If e.Row.RowType = DataControlRowType.DataRow Then
                
                Dim ADD_img As imagebutton = DirectCast(e.Row.FindControl("Add"), ImageButton)
                
 dim result as string
                

  result= Add_img.commandname.tostring & "." & Session.Item("ID")
    Add_img.attributes.Add("OnClick", "javascript:return openph(" & result & ")")           
end if     
 
                   
                End If


这篇关于网格视图行数据绑定不响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆