如何在asp.net的ListView/ListBox/GridView中创建动态LinkBut​​ton [英] How create dynamic LinkButton in ListView/ListBox/GridView in asp.net

查看:88
本文介绍了如何在asp.net的ListView/ListBox/GridView中创建动态LinkBut​​ton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在页面加载时在ListView/ListBox/GridView中添加链接按钮,在Page_Load()事件中,我想从数据库中查询数据,如果我得到1个数据,我将添加1个LinkBut​​ton如果我得到2个数据,而不是2个LinkBut​​ton,则我想添加更多的linkbutton取决于查询.
对于我来说,这很容易查询,但是在获取有关我的数据的信息之后,我无法为此添加LinkBut​​ton.
如:我有一个10行2列的表.我的查询结果是数据集表中的2行.现在,我要添加2个具有两行信息的LinkBut​​ton.

请帮助我.

I want to add link button in ListView/ListBox/GridView while my page is loaded, in the Page_Load() events I want to query data from database and if I get 1 data than I''ll add 1 LinkButton if I get 2 data than I''ll add 2 LinkButton in this way I want add more linkbutton depends on query.
It''s easy for me to query but, after getting information about my data I can''t add LinkButton for this respect.
Such as: I have a table with 10 rows and 2 column. My query''s result is 2 row which is in dataset''s table. Now, I want to add 2 LinkButton with the info of two rows.

Please help me.

推荐答案

例如,将链接按钮添加到TemplateField,然后可以添加命令参数并实现GridViewRowCommand并根据CommandName采取适当的操作.


For example add your link button to TemplateField and you can add command argument and implement GridViewRowCommand and take appropriate action based on CommandName.


<asp:templatefield headertext="Payer" controlstyle-width="100%" xmlns:asp="#unknown">
                                   <itemtemplate>
                                      <asp:linkbutton id="lbPayer" runat="server" text="<%# Eval("Payer") %>" commandargument="<%# Eval("Payer") %>" commandname="ViewPayer"></asp:linkbutton>
                                       </itemtemplate>
                                       <controlstyle width="100%"></controlstyle>
                               </asp:templatefield>


这篇关于如何在asp.net的ListView/ListBox/GridView中创建动态LinkBut​​ton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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