public int TextWidth(ref AxzCheckListBox.AxCheckListBox ctrl, string s) { int returnValue; Graphics e = ctrl.CreateGraphics(); SizeF sz; sz = e.MeasureString(s, ctrl.Font); returnValue = (int) (sz.Width); return returnValue; }
public void AddTabbedItem (AxzCheckListBox.AxCheckListBox ctrl, string str1, string str2) { short nTabs; int nWidth, nTextWidth;
nWidth = ctrl.ClientRectangle.Width - 150;
nTabs = 0; AxzCheckListBox.AxCheckListBox temp_AxzCheckListBoxAxCheckListBox = ctrl; nTextWidth = TextWidth(ref temp_AxzCheckListBoxAxCheckListBox, str1 + new string(System.Convert.ToChar("\t"), nTabs)); do { nTabs = (short) (nTabs + 1); AxzCheckListBox.AxCheckListBox temp_AxzCheckListBoxAxCheckListBox2 = ctrl; nTextWidth = TextWidth(ref temp_AxzCheckListBoxAxCheckListBox2, str1 + new string(System.Convert.ToChar("\t"), nTabs)); } while (nWidth >= nTextWidth); ctrl.AddItem(str1 + new string(System.Convert.ToChar("\t"), nTabs) + str2, Type.Missing ); } // Use this function convert System.Drawing.Color to a UInt32 static public UInt32 ToUInt32(Color c) { UInt32 returnValue; long i; i = c.R; i = i + 256 * c.G; i = i + 256 * 256 * c.B; returnValue = Convert.ToUInt32(i); return returnValue; } private void ChkList1_ClickEvent(object sender, System.EventArgs e) { short i; short nTotal;
// If Item 1 is not selected, item 2 must be grayed ChkList1.set_Grayed(2, ! ChkList1.get_Selected(1)); // If Item 2 is selected, item 1 must be selected ChkList1.set_Grayed(1, ChkList1.get_Selected(2)); ChkList1.set_ItemForeColor(1, ToUInt32(ChkList1.get_Selected(1)? Color.Blue: Color.Black));
if (ChkList1.ListIndex > -1) { if (! ChkList1.get_Grayed(ChkList1.ListIndex)) { ChkList1.set_ItemForeColor(ChkList1.ListIndex, ToUInt32(ChkList1.get_Selected(ChkList1.ListIndex)? Color.Blue: Color.Black)); } }
nTotal = 0; for (i = 0; i <= ChkList1.ListCount - 1; i++) { if (ChkList1.get_Selected(i)) { String sValue = ChkList1.get_List(i).Substring( ChkList1.get_List(i).IndexOf("$") + 1); nTotal += (short)UInt32.Parse(sValue); } } Label6.Text = "Total: US" + nTotal.ToString(); } }
ITEM的宽度??
不懂``什么概念??
document.getElementById("CheckBoxList1").rows[1].cells[0].style.width="200px";
</script>
CheckBoxList1.Items[1].Attributes.CssStyle.Add("width", "200px");
CheckBoxList1.Items[1].Attributes.Add("style", "width:200px");
我想是,但不知道可不可以,呵呵比较懒,还没有试过,呵呵
{
if (e.Item.ItemIndex > -1)
{
CheckBoxList ckbCategoryInfo = e.Item.FindControl("ckbCategoryInfo") as CheckBoxList; //给ckbCategoryInfo赋值数据源,并且绑定,这个没错
WebUtility.SetData(ckbCategoryInfo, CDict.GetDicts(CDictCategory.BusinessCategory.ID, nRoleID), "ID", "Name");
foreach (ListItem li in ckbCategoryInfo.Items)
{
li.Attributes.Add("Class", "test");
}
}
}我在datalist的ItemCreated事件中
用foreach这么给ckbCategoryInfo的item赋予class是不是不行啊?
我在页面上放了静态的checkboxlist用同样的方法就可以
是不是和页面的执行顺序有关?可以告诉我应该怎么改吗?急啊
{
li.Attributes.Add("Class", "test");
//li.Attributes.Add("width", "200px");
}
你这样不可以是吗?
over
{
int returnValue;
Graphics e = ctrl.CreateGraphics();
SizeF sz;
sz = e.MeasureString(s, ctrl.Font);
returnValue = (int) (sz.Width);
return returnValue;
}
{
short nTabs;
int nWidth, nTextWidth;
nWidth = ctrl.ClientRectangle.Width - 150;
nTabs = 0;
AxzCheckListBox.AxCheckListBox temp_AxzCheckListBoxAxCheckListBox = ctrl;
nTextWidth = TextWidth(ref temp_AxzCheckListBoxAxCheckListBox, str1 + new string(System.Convert.ToChar("\t"), nTabs));
do
{
nTabs = (short) (nTabs + 1);
AxzCheckListBox.AxCheckListBox temp_AxzCheckListBoxAxCheckListBox2 = ctrl;
nTextWidth = TextWidth(ref temp_AxzCheckListBoxAxCheckListBox2, str1 + new string(System.Convert.ToChar("\t"), nTabs));
} while (nWidth >= nTextWidth);
ctrl.AddItem(str1 + new string(System.Convert.ToChar("\t"), nTabs) + str2, Type.Missing );
} // Use this function convert System.Drawing.Color to a UInt32
static public UInt32 ToUInt32(Color c)
{
UInt32 returnValue;
long i;
i = c.R;
i = i + 256 * c.G;
i = i + 256 * 256 * c.B;
returnValue = Convert.ToUInt32(i);
return returnValue;
} private void ChkList1_ClickEvent(object sender, System.EventArgs e)
{
short i;
short nTotal;
// If Item 1 is not selected, item 2 must be grayed
ChkList1.set_Grayed(2, ! ChkList1.get_Selected(1));
// If Item 2 is selected, item 1 must be selected
ChkList1.set_Grayed(1, ChkList1.get_Selected(2));
ChkList1.set_ItemForeColor(1,
ToUInt32(ChkList1.get_Selected(1)? Color.Blue: Color.Black));
if (ChkList1.ListIndex > -1)
{
if (! ChkList1.get_Grayed(ChkList1.ListIndex))
{
ChkList1.set_ItemForeColor(ChkList1.ListIndex,
ToUInt32(ChkList1.get_Selected(ChkList1.ListIndex)? Color.Blue: Color.Black));
}
}
nTotal = 0;
for (i = 0; i <= ChkList1.ListCount - 1; i++)
{
if (ChkList1.get_Selected(i))
{
String sValue = ChkList1.get_List(i).Substring(
ChkList1.get_List(i).IndexOf("$") + 1);
nTotal += (short)UInt32.Parse(sValue);
}
}
Label6.Text = "Total: US" + nTotal.ToString();
}
}