怎么获得DataList中选中的Id

2025-02-24 13:16:22
推荐回答(2个)
回答1:

放一个label或literal,设visible=false
再放一个checkbox,footertemplate中放一个 id=btndel 的 button,设onclick= "btndel "

sub btndel(sender as object,e as eventargs)
dim delrecord as new stringbuilder
循环判断checkbox.checked=true,的话,将 delrecord.append(获取的id,就是那个label)
循环结束后,再调用一个过程 'call deletesub()
end sub

sub deletesub(delrecord )
sql= "delete from tablename where id in( " & delrecord .tostring & ") "
end sub

回答2:

可以在前台的button里面写一个oncommand="Function",CommandArgument='<%#Container.ItemIndex %>'
相当于点击按钮触发Function,参数是当前的行的下标...
后台Function里面找控件
可以用e.CommandArgument...Tostring一下,convert一下就得到选中的下标了