本文整理汇总了C#中System.Web.UI.WebControls.ListItem类的典型用法代码示例。如果您正苦于以下问题:C# ListItem类的具体用法?C# ListItem怎么用?C# ListItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ListItem类属于System.Web.UI.WebControls命名空间,在下文中一共展示了ListItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnLoad
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
/// </summary>
/// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!Page.IsPostBack)
{
for (var i = DateTime.Now.Year; i < DateTime.Now.Year + 3; i++)
{
var list = new ListItem
{
Text = i.ToString(),
Value = i.ToString()
};
ddlYear.Items.Add(list);
}
var month = Convert.ToDateTime("1/1/2000");
for (var i = 0; i < 12; i++)
{
var nextMonth = month.AddMonths(i);
var list = new ListItem
{
Text = nextMonth.ToString("MMMM"),
Value = nextMonth.Month.ToString()
};
ddlMonth.Items.Add(list);
}
ddlYear.SelectedValue = DateTime.Now.Year.ToString();
ddlMonth.SelectedValue = DateTime.Now.Month.ToString();
}
btnGoToDate.Click += btnGoToDate_Click;
}
示例2: BindDropDownNam
protected void BindDropDownNam()
{
//ddlNam.Items.Clear();
//lbMessage.Text = "";
//SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString);
//con.Open();
//string sql = "select year(ngay) Nam from CV_CapSo where ngay is not null group by year(ngay) order by year(ngay) desc";
//SqlCommand cmd = new SqlCommand(sql, con);
//SqlDataReader sdr = cmd.ExecuteReader();
//if (sdr.HasRows)
//{
// while (sdr.Read())
// {
// if (sdr.GetValue(sdr.GetOrdinal("Nam")).ToString() != null || sdr.GetValue(sdr.GetOrdinal("Nam")).ToString() != "")
// {
// int nam = Convert.ToInt32(sdr.GetValue(sdr.GetOrdinal("Nam")).ToString());
// ListItem li = new ListItem();
// li.Value = nam.ToString();
// li.Text = nam.ToString();
// ddlNam.Items.Add(li);
// }
// }
//}
//con.Close();
for (int i = 0; i < 5; i++)
{
ListItem li = new ListItem();
li.Value = (DateTime.Today.Year - i).ToString();
li.Text = (DateTime.Today.Year - i).ToString();
ddlNam.Items.Add(li);
}
}
示例3: LoadOptions
void LoadOptions()
{
ddlDistrict.DataSource = DistrictBO.GetAll(true);
ddlDistrict.DataValueField = "DistrictID";
ddlDistrict.DataTextField = "DistrictName";
ddlDistrict.DataBind();
ListItem li = new ListItem("[Gender]", "");
ddlGender.Items.Add(li);
li = new ListItem("Male", "M");
ddlGender.Items.Add(li);
li = new ListItem("Female", "F");
ddlGender.Items.Add(li);
li = new ListItem("[Status]", "");
ddlStatus.Items.Add(li);
li = new ListItem("Completed", "Completed");
ddlStatus.Items.Add(li);
li = new ListItem("Running", "Running");
ddlStatus.Items.Add(li);
//li = new ListItem("[Compensation]", "");
//ddlCompensation.Items.Add(li);
//li = new ListItem("Yes", "Yes");
//ddlCompensation.Items.Add(li);
//li = new ListItem("No", "No");
//ddlCompensation.Items.Add(li);
}
示例4: Page_Load
protected void Page_Load(object sender, System.EventArgs e)
{
sbmt.Text = ui.Text("create");
int NodeId = int.Parse(Request["nodeID"]);
int[] allowedIds = new int[0];
if (NodeId > 2)
{
cms.businesslogic.Content c = new cms.businesslogic.media.Media(NodeId);
allowedIds = c.ContentType.AllowedChildContentTypeIDs;
}
var documentTypeList = businesslogic.media.MediaType.GetAllAsList().ToList();
foreach (var dt in documentTypeList)
{
ListItem li = new ListItem();
li.Text = dt.Text;
li.Value = dt.Id.ToString();
if (NodeId > 2)
{
foreach (int i in allowedIds) if (i == dt.Id) nodeType.Items.Add(li);
}
// The Any check is here for backwards compatibility, if none are allowed at root, then all are allowed
else if (documentTypeList.Any(d => d.AllowAtRoot) == false || dt.AllowAtRoot)
nodeType.Items.Add(li);
}
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string app = gform("app");
int tempid = 0;
gnum(ref tempid, "id");
switch (app)
{
case "resettemplate":
reset_template(tempid);
showMessage("使用成功,刷新全部模板成功");
break;
default:
break;
}
if (!IsPostBack)
{
TemplateTypeDal dal = new TemplateTypeDal();
foreach (TemplateTypeInfo info in dal.view_list())
{
ListItem item = new ListItem(info.templateName, info.templateName);
if ("template/"+info.templateName == TEMPLATEPATH)
{
item.Selected = true;
}
main_template.Items.Add(item);
//else
//main_template.Items.Add(new ListItem(info.templateName, info.templateName));
}
}
}
示例6: Load_catesearch
private void Load_catesearch()
{
var list = per.Load_danhmuc_search(1);
if (list.Count > 0)
{
DataRelation relCat;
DataTable tbl = DataUtil.LINQToDataTable(list);
DataSet ds = new DataSet();
ds.Tables.Add(tbl);
tbl.PrimaryKey = new DataColumn[] { tbl.Columns["CAT_ID"] };
relCat = new DataRelation("Category_parent", ds.Tables[0].Columns["CAT_ID"], ds.Tables[0].Columns["CAT_PARENT_ID"], false);
ds.Relations.Add(relCat);
DataSet dsCat = ds.Clone();
DataTable CatTable = ds.Tables[0];
DataUtil.TransformTableWithSpace(ref CatTable, dsCat.Tables[0], relCat, null);
Drcate_search.DataSource = dsCat.Tables[0];
Drcate_search.DataTextField = "CAT_NAME";
Drcate_search.DataValueField = "CAT_ID";
Drcate_search.DataBind();
}
ListItem l = new ListItem("Tất cả", "0");
l.Selected = true;
Drcate_search.Items.Insert(0, l);
}
示例7: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
templateID = int.Parse(Request["id"]);
Template t = new Template(templateID);
if (Skinning.StarterKitGuid(templateID).HasValue)
{
p_apply.Visible = true;
string currentSkin = Skinning.GetCurrentSkinAlias(templateID);
int templateRoot = FindTemplateRoot((CMSNode)t);
dd_skins.Items.Add("Choose...");
foreach (KeyValuePair<string,string> kvp in Skinning.AllowedSkins(templateRoot))
{
ListItem li = new ListItem(kvp.Value, kvp.Key);
if (kvp.Key == currentSkin)
li.Selected = true;
dd_skins.Items.Add(li);
}
if (!string.IsNullOrEmpty(Skinning.GetCurrentSkinAlias(templateID)))
{
ph_rollback.Visible = true;
}
}
}
示例8: Page_Load
protected void Page_Load(object sender, System.EventArgs e)
{
sbmt.Text = ui.Text("create");
int NodeId = int.Parse(Request["nodeID"]);
int[] allowedIds = new int[0];
if (NodeId > 2)
{
cms.businesslogic.Content c = new cms.businesslogic.media.Media(NodeId);
allowedIds = c.ContentType.AllowedChildContentTypeIDs;
}
foreach(cms.businesslogic.ContentType dt in cms.businesslogic.media.MediaType.GetAll)
{
ListItem li = new ListItem();
li.Text = dt.Text;
li.Value = dt.Id.ToString();
if (NodeId > 2)
{
foreach (int i in allowedIds) if (i == dt.Id) nodeType.Items.Add(li);
}
else
nodeType.Items.Add(li);
}
}
示例9: Innit
/// <summary>
/// 初始化
/// </summary>
private void Innit()
{
ListItem nullItems = new ListItem();
nullItems.Value = "";
nullItems.Text = "请选择";
//初始化项目编号
ProjectNO_Input.Items.Add(nullItems);
List<T_ProjectDicEntity> projectlist = BusinessFacadeShanlitech_Location.GetProjectList();
foreach (T_ProjectDicEntity r in projectlist)
{
ListItem item = new ListItem();
item.Text = r.ProjectName;
item.Value = r.ID.ToString();
ProjectNO_Input.Items.Add(item);
}
//初始化申请人
Applicant_Input.Items.Add(nullItems);
ArrayList userlist = BusinessFacadeShanlitech_Location.GetUserList();
foreach (sys_UserTable r in userlist)
{
ListItem item = new ListItem();
item.Value = r.UserID.ToString();
item.Text = r.U_LoginName;
if (!r.U_LoginName.Equals(""))
{
Applicant_Input.Items.Add(item);
}
}
}
示例10: initdata
protected void initdata()
{
/*
DropDownListDept.Items.Clear();
List<Department> deps = BLL.admin.department.DepartmentManagement.getDepartments();
foreach (Department dept in deps)
{
ListItem item = new ListItem();
item.Text = dept.Name;
item.Value = dept.Name;
DropDownListDept.Items.Add(item);
}
*/
DropDownListType.Items.Clear();
ListItem lin = new ListItem("");
DropDownListType.Items.Add(lin);
List<KQ_AttendanceType> t = BLL.Application.KQ.Attendance.MyAttendance.getAttendanceType();
foreach (KQ_AttendanceType li in t)
{
ListItem l = new ListItem();
l.Text = li.name;
l.Value = li.Id.ToString();
DropDownListType.Items.Add(l);
}
AspNetPager1.PageSize = BLL.pub.PubClass.PAGE_SIZE;
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Page.MaintainScrollPositionOnPostBack = true;
HttpCookie userCookie;
HttpCookie passCookie;
userCookie = Request.Cookies["UserID"];
passCookie = Request.Cookies["UserPass"];
if (userCookie == null || passCookie == null)
{
if (!IsPostBack)
{
ListBox1.Items.Clear();
ListBox1.Width = 100;
ListBox1.Height = 60;
ListItem f = new ListItem("Female", "0");
ListItem m = new ListItem("Male", "1");
ListBox1.Items.Add(f);
ListBox1.Items.Add(m);
}
}
else
{
Response.Redirect("..//Default.aspx");
}
}
示例12: MakeTree
/// <summary>
/// 绑定生成一个有树结构的下拉菜单
/// </summary>
/// <param name="dtNodeSets">菜单记录数据所在的表</param>
/// <param name="strParentColumn">表中用于标记父记录的字段</param>
/// <param name="strRootValue">第一层记录的父记录值(通常设计为0或者-1或者Null)用来表示没有父记录</param>
/// <param name="strIndexColumn">索引字段,也就是放在DropDownList的Value里面的字段</param>
/// <param name="strTextColumn">显示文本字段,也就是放在DropDownList的Text里面的字段</param>
/// <param name="drpBind">需要绑定的DropDownList</param>
/// <param name="i">用来控制缩入量的值,请输入-1</param>
public static void MakeTree(DataTable dtNodeSets, string strParentColumn, string strRootValue, string strIndexColumn, string strTextColumn, DropDownList drpBind, int i)
{
//每向下一层,多一个缩入单位
i++;
DataView dvNodeSets = new DataView(dtNodeSets);
dvNodeSets.RowFilter = strParentColumn + "=" + strRootValue;
string strPading = ""; //缩入字符
//通过i来控制缩入字符的长度,我这里设定的是一个全角的空格
for (int j = 0; j < i; j++)
strPading += " ";//如果要增加缩入的长度,改成两个全角的空格就可以了
foreach (DataRowView drv in dvNodeSets)
{
TreeNode tnNode = new TreeNode();
ListItem li = new ListItem(strPading + "├" + drv[strTextColumn].ToString(), drv[strIndexColumn].ToString());
drpBind.Items.Add(li);
MakeTree(dtNodeSets, strParentColumn, drv[strIndexColumn].ToString(), strIndexColumn, strTextColumn, drpBind, i);
}
//递归结束,要回到上一层,所以缩入量减少一个单位
i--;
}
示例13: ddlPolicyGroup_SelectedIndexChanged
protected void ddlPolicyGroup_SelectedIndexChanged(object sender, EventArgs e)
{
ddlSchedule.Items.Clear();
ddlStandard.Items.Clear();
ddlQuery.SelectCommand = "SELECT DISTINCT ScheduleUID, ScheduleName FROM compiledpolicies WHERE PolicyGroupUID " + ddlPolicyGroup.SelectedValue.ToString() + " ORDER BY ScheduleName";
//Response.Write("ddlSchedule ddlQuery.SelectCommand (ddlPolicyGroup_SelectedIndexChanged): " + ddlQuery.SelectCommand.ToString() + "<br>");
SqlDataReader sqlReader = (SqlDataReader)ddlQuery.Select(DataSourceSelectArguments.Empty);
if (sqlReader.HasRows)
{
while (sqlReader.Read())
{
ListItem item = new ListItem(sqlReader[1].ToString(), "= " + sqlReader[0].ToString(), true);
ddlSchedule.Items.Add(item);
}
}
ListItem scheduleall = new ListItem("Narrow results by schedule...", " != ''", true);
scheduleall.Selected = true;
ddlSchedule.Items.Add(scheduleall);
ddlQuery.SelectCommand = "SELECT DISTINCT StandardUID, StandardName FROM compiledpolicies WHERE PolicyGroupUID " + ddlPolicyGroup.SelectedValue.ToString() + " AND ScheduleUID " + ddlSchedule.SelectedValue.ToString() + " ORDER BY StandardName";
//Response.Write("ddlStandard ddlQuery.SelectCommand (ddlPolicyGroup_SelectedIndexChanged): " + ddlQuery.SelectCommand.ToString() + "<br>");
sqlReader = (SqlDataReader)ddlQuery.Select(DataSourceSelectArguments.Empty);
if (sqlReader.HasRows)
{
while (sqlReader.Read())
{
ListItem item = new ListItem(sqlReader[1].ToString(), "= " + sqlReader[0].ToString(), true);
ddlStandard.Items.Add(item);
}
}
ListItem standardall = new ListItem("Narrow results by schedule...", " != ''", true);
standardall.Selected = true;
ddlStandard.Items.Add(standardall);
}
示例14: OnPreRender
protected override void OnPreRender(EventArgs e)
{
if ((lstLists.SelectedIndex > -1) & (!UpdateListProperties))
{
SelectedListId = new Guid(lstLists.SelectedValue);
}
lstLists.Items.Clear();
SPWeb site = SPContext.Current.Web;
foreach (SPList list in site.Lists)
{
ListItem listItem = new ListItem(list.Title, list.ID.ToString());
lstLists.Items.Add(listItem);
}
// when the page reloads, default the selected item to the current list
if (SelectedListId != Guid.Empty)
{
lstLists.Items.FindByValue(SelectedListId.ToString()).Selected = true;
}
if (UpdateListProperties)
{
SPList list = SPContext.Current.Web.Lists[SelectedListId];
lblListTitle.Text = list.Title;
lblListID.Text = list.ID.ToString().ToUpper();
lblListIsDocumentLibrary.Text = (list is SPDocumentLibrary).ToString();
lblListIsHidden.Text = list.Hidden.ToString();
lblListItemCount.Text = list.ItemCount.ToString();
lnkListUrl.Text = list.DefaultViewUrl;
lnkListUrl.NavigateUrl = list.DefaultViewUrl;
}
}
示例15: dtgUsers_PreRender
protected void dtgUsers_PreRender(object sender, EventArgs e)
{
if (dtgUsers.BottomPagerRow != null)
{
((Label)dtgUsers.BottomPagerRow.FindControl("lbTotalPages")).Text = dtgUsers.PageCount.ToString();
//This makes the first and last button disappear when on the first and last pages.
((LinkButton)dtgUsers.BottomPagerRow.FindControl("lbtnFirst")).Visible = dtgUsers.PageIndex != 0;
((LinkButton)dtgUsers.BottomPagerRow.FindControl("lbtnLast")).Visible = dtgUsers.PageCount != (dtgUsers.PageIndex + 1);
DropDownList ddlistPageof = (DropDownList)dtgUsers.BottomPagerRow.FindControl("ddlPageItems");
ddlistPageof.SelectedIndex = ddlistPageof.Items.IndexOf(ddlistPageof.Items.FindByValue(ViewState["DropDownPageItems"].ToString()));
DropDownList ddlistPageno = (DropDownList)dtgUsers.BottomPagerRow.FindControl("ddlNumberPages");
ddlistPageno.Items.Clear();
for (int i = 1; i <= dtgUsers.PageCount; i++)
{
ListItem liTemp = new ListItem();
liTemp.Text = i.ToString();
liTemp.Value = i.ToString();
ddlistPageno.Items.Add(liTemp);
}
if (dtgUsers.PageCount != 0)
{
ddlistPageno.SelectedIndex = dtgUsers.PageIndex;
ddlistPageno.DataBind();
}
}
}