gridview项目模板 [英] gridview item template

查看:77
本文介绍了gridview项目模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想根据特定条件在gridview项模板中添加"Switch Case"以进行一些附加控制.


请给我任何建议
在此先感谢

Govind

Hi Guys,

I want to add "Switch Case" in gridview item template for some addition control according to specific condition.


Plz give me any suggestion
Thanks in advance

Govind

推荐答案



在gridview项模板中没有所谓的switch case.添加所有控件,无论您想在所有条件下显示什么.在源代码中添加visible = "false".

现在在gridview ItemDatabound event中使用switch语句,并根据您的条件,只需找到控件并制作visible true.

Hi,

There is nothing called switch case in gridview item template. Add all the controls whatever you want to display from all conditions. Add visible = "false" in source.

Now in gridview ItemDatabound event use the switch statement and based on your conditions, just find the controls and make visible true.

Protected void GridView1_ItemDataBound(object sender, GridViewItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.Item)
   {
        switch(condition)
        {
            case 1 :
                   {
                      ((Label)e.Item.FindControl("Label1")).visible=true;
                      break;
                   }
           case 2 :
                   {
                      ((Label)e.Item.FindControl("Label2")).visible=true;
                      break;
                   }

        }
   }
}



在这里,我也采用类似的标签,您可以在项目模板中选择任何控件,并根据条件进行渲染.

希望对您有所帮助.



here i have taken label similarly you can have any controls of your choice inside item template and render based on the condition.

hope it helps.


这篇关于gridview项目模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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