欧美日韩一区二区三区四区不卡,日韩欧美视频一区二区三区四区,久久精品欧美一区二区三区不卡,国产精品久久久乱弄

咨詢電話:186 7916 6165 咨詢電話:186 7916 6165 (微信同號)    在線QQ:181796286
NEWS BLOG ·
學無止境
關注開優網絡 關注前沿
ASP.NET Web 開發之購物車
ASP.NET Web 開發之代碼生成及增、刪、改

ASP.NET常用服務器控件方法及屬性

發表日期:2015-09-26    文章編輯:南昌開優網絡    瀏覽次數:4270    標簽:ASP.NET應用

//控件DorpDownList
ddltitle.DataSource=new Xiaobin.Shop.DAL.HelpDAL().GetList(""); //指定數據源
ddltitle.DataTextField="title";    //顯示的文本
ddltitle.DataValueField="id";    //選擇的字段
ddltitle.DataBind();    //綁定
ddltitle.Items.Add(new ListItem("選擇類別", "0"));    //在數據源最后加上一項
ddltitle.Items.Insert(0,new ListItem("選擇類別", "0"));    //在指定的位置加上一項

//綁定DataSet數據
string title=Request.QueryString["title"];
if(string.IsNullOrEmpty(title))
{
    title="關于我們";
}
litH1.Text=title;
title=xiaobin.Utility.Tool.GetSafeSQL(title);
DataSet ds=new DAL.HelpDAL().GetList("title='"+title+"'");    //綁定DataSet
if(ds.Tables.Count>0&&ds.Table[0].Rows.Count>0)    //如果表的數量和第一個表的行數大于0
{
    litbody.Text=ds.Table[0].Rows[0]["body"].ToString(); //取出第一個表的第一行的數據
}

//Repeater的內循環事件
外循環
private void BindRep()
{
rep.DataSource = dao.GetList("*", "createdate", "asc", anp.PageSize, anp.CurrentPageIndex, GetCond());
rep.DataBind();
}
內循環     雙擊事件中的ItemDataBound    如顯示樓層方法
int x = 0;    
protected void rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Panel pan = e.Item.FindControl("pan") as Panel;    //FindControl 嘗試轉換及rep控件的服務器控件
Literal litx = e.Item.FindControl("litx") as Literal;
Literal litreply = e.Item.FindControl("litreply") as Literal;    
if (litreply.Text.Trim().Length == 0)    
{
pan.Visible = false;
}
else
{
pan.Visible = true;
}
litx.Text = (anp.StartRecordIndex + x).ToString();    //StartRecordIndex 為anp控件中的當前索引   升序排序
                litx.Text=(anp.RecordCount - (anp. StartRecordIndex + x).Tostring());    //降序排序
x++;
}
}

//Repeater控件的嵌套使用
//綁定頂級分類     
repca1.DataSource = new DAL.CategoryDAL().GetListArray("pid=0");
repca1.DataBind();
//循環repca1
protected void repca1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
        //ListItemType.Item 奇數行  ListItemType.AlternatingItem 偶數行
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Repeater repca2 = e.Item.FindControl("repca2") as Repeater;
                //在rep1中加上隱藏域用于綁定rep2即 value='<%#Eval("id")>'
HiddenField hfid1 = e.Item.FindControl("hfid1") as HiddenField;
Repeater repca3 = e.Item.FindControl("repca3") as Repeater;
repca2.DataSource = new DAL.CategoryDAL().GetListArray("pid=" + hfid1.Value);
repca2.DataBind();
}
}
//循環repca2
protected void repca2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Repeater repca3 = e.Item.FindControl("repca3") as Repeater;
HiddenField hfid2 = e.Item.FindControl("hfid2") as HiddenField;
repca3.DataSource = new DAL.CategoryDAL().GetListArray("pid=" + hfid2.Value);
repca3.DataBind();
}
}
//Repeater控件的分割屬性
SeparatorTemplate

//通過Model獲取RadioButtonList、DropDownList選中的值
ListItem li = rademail.Items.FindByValue(model.isopenemail.ToString()); //
if (li != null)
{
li.Selected = true;    //列表項等于model中的字段值時為真及顯示選中的字段
}
li = radsex.Items.FindByValue(model.sex.ToString());
if (li != null)
{
li.Selected = true;
}
li = ddlprovince.Items.FindByValue(model.province);
ddlprovince.ClearSelection(); //清空dll再重新獲取
if (li != null)
{
li.Selected = true;
}
li = ddlcity.Items.FindByValue(model.city);
ddlcity.ClearSelection();
if (li != null)
{
li.Selected = true;
}

//DropDownList的條件綁定
選擇查看方式:
<asp:DropDownList ID="ddlorder" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlorder_SelectedIndexChanged">
<asp:ListItem Text="↓按上架時間降序排列" Value="0"></asp:ListItem>
<asp:ListItem Text="↑按上架時間升序排列" Value="1"></asp:ListItem>
<asp:ListItem Text="↓按會員價降序排列" Value="2"></asp:ListItem>
<asp:ListItem Text="↑按會員價升序排列" Value="3"></asp:ListItem>
</asp:DropDownList>
//綁定列表
private void BindRep()
{
string order = "createdate";
string ordertype = "desc";
switch (ddlorder.SelectedValue)
{
case "0":
order = "createdate";
ordertype = "desc";
break;
case "1":
order = "createdate";
ordertype = "asc";
break;
case "2":
order = "memberprice";
ordertype = "desc";
break;
case "3":
order = "memberprice";
ordertype = "asc";
break;
default:
break;
}
rep.DataSource = new DAL.ProductDAL.GetList("*", order, ordertype, anp.PageSize, anp.CurrentPageIndex, GetCond());
rep.DataBind();
}
//選擇排序方式
protected void ddlorder_SelectedIndexChanged(object sender, EventArgs e)
{
BindRep();
}

TextMode="MultiLine"  前臺顯示原樣顯示出box.Replace("\n", "<br />")    //把換行替換成br

.Net中頁面刷新時保持滾動條不動
<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="Default" Title="" MaintainScrollPositionOnPostback="true" %>
MaintainScrollPositionOnPostback屬性可以讓滾動條回到原位置
主站蜘蛛池模板: 乐清市| 武义县| 韶山市| 鄂托克前旗| 贡嘎县| 克什克腾旗| 阳谷县| 大冶市| 永年县| 增城市| 新建县| 宁河县| 合江县| 盐池县| 汉沽区| 嘉兴市| 汝州市| 芜湖市| 惠来县| 和田县| 桐柏县| 洪雅县| 江山市| 莒南县| 沂水县| 新泰市| 乾安县| 革吉县| 兴义市| 庆安县| 鄂托克前旗| 泸水县| 中超| 六安市| 昂仁县| 醴陵市| 张家口市| 浏阳市| 甘泉县| 惠水县| 和田市|