数据列表控件 [英] datalist control

查看:80
本文介绍了数据列表控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我的aspx页面中有一个DataList控件.它包含一个链接按钮和标签.我希望单击链接按钮时链接按钮可以隐藏并显示标签.我已经尝试过了,但是失败了.请指导.

Hi All,
I have a DataList control in my aspx page. It consist a linkbutton and label. I want that on clicking link button the link button get hide and label become visible. I have tried like this but failed. Please guide.

protected void DataList4_ItemCommand(object source, DataListCommandEventArgs e)
   {
       if (e.CommandName == "lnkhead")
       {
           LinkButton lnk = (LinkButton)e.CommandSource;

           foreach (DataListItem item in DataList4.Items)
           {
               Label lbl = (Label)item.FindControl("lblhead");
               lbl.Visible = true;

           }
               lnk.Visible = false;

       }
   }

推荐答案

删除foreach块
Remove foreach block
protected void DataList4_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "lnkhead")
        {
            LinkButton lnk = (LinkButton)e.CommandSource;            
            Label lbl = (Label)e.Item.FindControl("lblhead");
            lbl.Visible = true;
            lnk.Visible = false;
           
        }
    }


这篇关于数据列表控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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