通过CommandArgument在datalist中查找控件 [英] find control in datalist by CommandArgument

查看:108
本文介绍了通过CommandArgument在datalist中查找控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从JOKE的数据库ID中检索,如果它是否喜欢



所有我想在命令范围内找到我的数据列表中的控件我检索

解决方案

为Control提供命令名字段,如下所示:



 <   ItemTemplate  >  
< asp:ImageButton ID = Image1 runat = 服务器 CommandArgument =' <% #Eval( product_id %> ' CommandName = 点击 高度 = 200px < span class =code-attribute> ImageUrl =' <% #Eval( url %> ' 宽度 = 200px / >
< / ItemTemplate >







然后代码落后:



  protected   void  Datalist1_ItemCommand( object  source ,DataListCommandEventArgs e)
{
if (e.CommandName == < span class =code-string> click)
{
// 你的逻辑
}
}


在项目命令事件中你可以找到如下控件

例如,如果你有一个id为Txt1的TextBox



 T extBox txt1 = e.Item.FindControl(  Txt1 as  TextBox; 


i retrieve from data base id of JOKE and if it like or not

all what i want to find the control inside my data list with the commandargument= id that i retrieve

解决方案

Give command name field for Control like this:

<ItemTemplate>
<asp:ImageButton ID="Image1" runat="server" CommandArgument='<%# Eval("product_id") %>' CommandName="click" Height="200px" ImageUrl='<%# Eval("url")%>' Width="200px" />
        </ItemTemplate>




and then in code behind:

protected void Datalist1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "click")
        {
            // your logic
        }
     }


inside item command event you can find controls as below
e.g if you have TextBox with id Txt1

TextBox txt1 = e.Item.FindControl("Txt1") as TextBox; 


这篇关于通过CommandArgument在datalist中查找控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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