can i set the visibility of an item of datalist to false?

  • Thread starter Thread starter miladhatam
  • Start date Start date
M

miladhatam

can i set the visibility of an item of datalist to false ?
for eg :

Item.visible = false;
 
i did it myself
protected void Page_Load(object sender, EventArgs e)
{
int range = 2;
int p = Convert.ToInt16(Request["page"].ToString());
if ( p ==0)
p=1;
if (DataList1.Items.Count % range > 0)
{

numeric1.listSize = (DataList1.Items.Count / range) + 1;
}
if (DataList1.Items.Count % range == 0)
{
numeric1.listSize = (DataList1.Items.Count / range);

}
if (p == 1)
{
for (int i = range; i < DataList1.Items.Count ; i++)
{
DataList1.Items.Controls.Clear();
}
}
else
{
for (int i = 0; i < (p-1)*range ; i++)
{
DataList1.Items.Controls.Clear();
}

for (int i = range*(p) ; i < DataList1.Items.Count; i++)
{
DataList1.Items.Controls.Clear();
}

}
}
 
Just a FYI.
1. this code
if (DataList1.Items.Count % range > 0)
{

numeric1.listSize = (DataList1.Items.Count / range) + 1;
}
if (DataList1.Items.Count % range == 0)
{
numeric1.listSize = (DataList1.Items.Count / range);

}
Can be simplified to
numeric1.listSize = (DataList1.Items.Count + range-1) / range;

2. This code
for (int i = range; i < DataList1.Items.Count ; i++)
{
DataList1.Items.Controls.Clear();
}

Can be written without brackets. It's matter of preference but i think it's
easier to read

for (int i = range; i < DataList1.Items.Count ; i++)
DataList1.Items.Controls.Clear();


George



i did it myself
protected void Page_Load(object sender, EventArgs e)
{
int range = 2;
int p = Convert.ToInt16(Request["page"].ToString());
if ( p ==0)
p=1;
if (DataList1.Items.Count % range > 0)
{

numeric1.listSize = (DataList1.Items.Count / range) + 1;
}
if (DataList1.Items.Count % range == 0)
{
numeric1.listSize = (DataList1.Items.Count / range);

}
if (p == 1)
{
for (int i = range; i < DataList1.Items.Count ; i++)
{
DataList1.Items.Controls.Clear();
}
}
else
{
for (int i = 0; i < (p-1)*range ; i++)
{
DataList1.Items.Controls.Clear();
}

for (int i = range*(p) ; i < DataList1.Items.Count; i++)
{
DataList1.Items.Controls.Clear();
}

}
}
 
Back
Top