DataList ItemDataBound事件 [英] DataList ItemDataBound Event

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

问题描述

我已经为DataList ItemDataBound事件编写了以下代码来更改我的图像的可见性。

此代码适用于DataList中的所有项目,但不会给我任何输出为最后一项。 DataList的最后一项仍未受影响。任何人都可以建议我应该做哪些更改来影响我最后一个DataList项目?



我的代码如下:



I have written the following code for DataList ItemDataBound event to change my image''s visibility.
This code works fine for all the items in the DataList but doesn''t give me any output for the last item. The Last Item of DataList remains uneffected. Can anyone suggest what changes should I make to affect my last item of DataList also?

My code is as follows:

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
   {
       int i;
       ////foreach (DataListItem di in DataList1.Items)
       for  (i=0; i < DataList1.Items.Count; i++)
       {
           if (((DataList)(DataList1.Items[i].FindControl("DataList3"))).Items.Count <= 0)
           {
               ((System.Web.UI.WebControls.Image)(DataList1.Items[i].FindControl("Image40"))).Visible = true;

           }
           else
           {
               ((System.Web.UI.WebControls.Image)(DataList1.Items[i].FindControl("Image40"))).Visible = false;
           }
       }
   }

推荐答案

它无法提供帮助问题。

但如果条件可以删除。只是一个建议。

It is not going to help with the issue.
But that if condition can be removed. Just a suggestion.
for  (i=0; i < DataList1.Items.Count; i++)
{
  ((System.Web.UI.WebControls.Image)(DataList1.Items[i].FindControl("Image40"))).Visible = (((DataList)(DataList1.Items[i].FindControl("DataList3"))).Items.Count <= 0);
}


protected void dg_outstation_ItemDataBound(object sender,DataGridItemEventArgs e)

{



{

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)



DataTable dt2 = dl.filltbl(select * from tbl_city where id =+ Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,city_id)。ToString())+ );

((Literal)e.Item.FindControl(lt_city))。Text = dt2.Rows [0] [city]。ToString();



DataTable dt1 = dl.filltbl(select * from tbl_outstation where id =+ Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,id)。ToString() )+和状态= 1);

if(dt1.Rows.Count> 0)

{

((LinkBut​​ton) e.Item.FindControl(lnk_active))。Visible = false;

((LinkBut​​ton)e.Item.FindControl(lnk_suspend))。Visible = true;

((ImageButton)e.Item.FindControl(img_active))。Visible = false;

((ImageButton)e.Item.FindControl(img_suspend))。Visible = true;





}

其他

{

((LinkBut​​ton)e.Item.FindControl(lnk_active))。Visible = true;

((LinkBut​​ton)e.Item.FindControl(lnk_suspend))。Visible = false;

((ImageButton)e.Item.FindControl(img_active))。可见= true;

((ImageButton)e.Item.FindControl(img_suspend))。Visible = false;}



} < br $>
}}



}
protected void dg_outstation_ItemDataBound(object sender, DataGridItemEventArgs e)
{

{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

DataTable dt2 = dl.filltbl("select * from tbl_city where id=" + Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "city_id").ToString()) + "");
((Literal)e.Item.FindControl("lt_city")).Text = dt2.Rows[0]["city"].ToString();

DataTable dt1 = dl.filltbl("select * from tbl_outstation where id=" + Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "id").ToString()) + "and status=1");
if (dt1.Rows.Count > 0)
{
((LinkButton)e.Item.FindControl("lnk_active")).Visible = false;
((LinkButton)e.Item.FindControl("lnk_suspend")).Visible = true;
((ImageButton)e.Item.FindControl("img_active")).Visible = false;
((ImageButton)e.Item.FindControl("img_suspend")).Visible = true;


}
else
{
((LinkButton)e.Item.FindControl("lnk_active")).Visible = true;
((LinkButton)e.Item.FindControl("lnk_suspend")).Visible = false;
((ImageButton)e.Item.FindControl("img_active")).Visible = true;
((ImageButton)e.Item.FindControl("img_suspend")).Visible = false;}

}
}}

}


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

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