控件:
一,選項控件:
l Dropdownlist:
數據綁定:
方法1:
this.ddlFatherIndustry.DataSource=dt;
this.ddlFatherIndustry.DataTextField="名稱";
this.ddlFatherIndustry.DataValueField="fatherid";
this.ddlFatherIndustry.DataBind();
方法2:
ddlUnite.Items.Clear();//清楚所有選項
this.ddlUnite.Items.Add(new ListItem("請選擇部門","-1"));
DataTable objTable=new DataTable();
objManage=new Lilosoft.PA.EAccount.Manage();
ret=objManage.GetAllDept(out objTable,out strErr);
foreach(DataRow row in objTable.Rows)
{
this.ddlUnite.Items.Add(new ListItem(row["name"].ToString(),row["id"].ToString()));
}
得到選中的值:ddlPersonnel.SelectedItem.Value
加入兩個頁面有相同的Dropdownlist,一個頁面選中一個值到另一個頁面,那麼另一個頁面的ddl要初始本身包含的選中項:
if( Request["Dept"] != null )
{
string dept = Request["Dept"].ToString();
ddlDept.SelectedIndex=ddlDept.Items.IndexOf(ddlDept.Items.FindByValue(dept));
}
超連接:
Hyperlink3.NavigateUrl = "PersonnelCompare.aspx?Cycle=" + ddlCycle.SelectedItem.Value + "&Dept=" + ddlDept.SelectedItem.Value + "&Personnel=" + ddlPersonnel.SelectedItem.Value ;
l RadioButtonList
1, 得到選定項的值:屬性:RadioButtonList1.SelectedValue
2, 設置選中項:RadioButtonList1.Items[0].Selected = true;
二,DataGrid
DataGrid: e.Item.ItemIndex 下標索引Header是 -1,每行數據Item是從 0 開始的。
數據綁定時(事件:DGList_ItemDataBound,即綁定每行後執行的事件)
if(e.Item.ItemIndex==-1)return;
int id=int.Parse(e.Item.Cells[0].Text);
e.Item.Cells[1].Text=objOrganize.GetDeptNameByID(id,out strErr);
#region 2006-7-18 加入連接
string TempDept = e.Item.Cells[1].Text;
e.Item.Cells[4].Text = ""+ e.Item.Cells[4].Text +"";
事件出發(事件:dgList_ItemCommand,即在DataGrid中出發事件)
//根據CommandName的名字來判斷做什麼。//
// 觸發刪除事件
if(e.CommandName == "delete")
{
string id = e.Item.Cells[0].Text;
DataTable td1 = new DataTable();
objIndicatorMgmt.ListPersonByContentID(id,out td1,out strErr);
if(td1.Rows.Count > 0)
{
Response.Write("<script>alert('請先刪除該考覈內容所對應的責任人!')</script>");
return;
}
objIndicatorMgmt.DelContentById(id,out strErr);
dgList.EditItemIndex = -1;
DGDataBind();
}
改變DataGrid每行數據,但不改變表頭
if(e.Item.ItemType !=ListItemType.Header)
{
e.Item.Cells[6].Text=(e.Item.Cells[6].Text=="False"?"否":"是");
e.Item.Cells[7].Text=(e.Item.Cells[7].Text=="False"?"否":"是");
}
三,HyperLink1:超鏈接控件導航設置
HyperLink1.NavigateUrl = "ResultSearch_Chart.aspx?period="+ddlCycle.SelectedValue;
其它常用:
GridView中某一列隱藏,並能取到值。
.hidden { display:none;}
在gridview中某一列上 ItemStyle-CssClass="hidden" HeaderStyle-CssClass="hidden"
光爆效果:DataGrid1_ItemDataBound事件
if (e.Item.ItemType !=ListItemType.Header)
{ //給每行加js光爆效果
e.Item.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.backgroundColor='#EEEEFF'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=color");
}
小窗口、頁面打開、彈出、關閉:
Response.Write("<script>window.open('"+url+"','每月稅收明細','height=350,width=700,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')</script>");
返回JS:
1,關閉窗口:Response.Write("<script>window.close();</script>");
Response.Write("<script>alert('修改成功!');</script>");
3, 彈出對話框並跳轉(利用工具類JavaScriptOB): JavaScriptOB.AlertAndRedirect("您沒有審覈權限!", "JBu_List.aspx");
4, 顯示父頁面,本頁面關閉,父頁面刷新
Response.Write("<script> window.opener.location.href=window.opener.location.href;window.close();</script>");
5, 彈出子頁面:
function OpenClientInfo(url,width,height) {
if (width == "")
var w = 700;
else
var w = width;
if (height == "")
var h = 500;
else
var h = height;
var lPos = (screen.width) ? (screen.width-w)/2 : 0;
var tPos = (screen.height) ? (screen.height-h)/2 : 0;
window.open(url, "", "toolbar=0,location=0,directories=1,status=0,menubar=0,scrollbars=yes,resizable=0,width=" + w + ",height=" + h + ",left=" + lPos + ",top=" + tPos);
}
//在.cs頁面加
btnSupplyAdd.Attributes.Add("onclick", "javascript:OpenClientInfo('Client_Supply_Dealer.aspx?clientcode=" + clientcode + "','','630px')");
6,刪除確認:
OnClientClick="return confirm('確定刪除?')"
6, 點擊按鈕直接跳轉:onClick="javascript:location.href='SmsGroup?oprater=List'"
隱藏域:
可以隱藏,但在j2ee中,控件disabled=true後,得不到這個html控件的值