protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.Header)
{
foreach(TableCell cell in e.Row.Cells)
cell.Attributes.Add("style","FONT-WEIGHT:normal");
}
}
參考:http://topic.csdn.net/t/20060712/22/4876677.html#
2009年1月15日 星期四
2009年1月8日 星期四
使用SqlDataSource時,請注意
當select的語法很短及易,就會利用SqlDataSource來達成查詢資料的功效
.aspx
SqlDataSource
ConnectionString="連結字串"
SelectCommand="SQL語法"
SelectCommandType="text"
.cs
SqlDataSource.SelectParameters.Clear();
SqlDataSource.SelectParameters.Add("keyword", TypeCode.String, tbx_keyword.Text.Trim());
SqlDataSource.Select(new DataSourceSelectArguments());
正常來說,以上的設定就可以完成查詢的功能,但若發現如無查詢條件時,應該獲得所有的資料清單,卻無資料;反之,就能獲得查詢的資料清單,這時就要多設定
SqlDataSource.SelectParameters["keyword"].ConvertEmptyStringToNull = false;
因當SqlDataSource遇到空字串時,會自動轉換成null,所以要關閉此功能屬性
.aspx
SqlDataSource
ConnectionString="連結字串"
SelectCommand="SQL語法"
SelectCommandType="text"
.cs
SqlDataSource.SelectParameters.Clear();
SqlDataSource.SelectParameters.Add("keyword", TypeCode.String, tbx_keyword.Text.Trim());
SqlDataSource.Select(new DataSourceSelectArguments());
正常來說,以上的設定就可以完成查詢的功能,但若發現如無查詢條件時,應該獲得所有的資料清單,卻無資料;反之,就能獲得查詢的資料清單,這時就要多設定
SqlDataSource.SelectParameters["keyword"].ConvertEmptyStringToNull = false;
因當SqlDataSource遇到空字串時,會自動轉換成null,所以要關閉此功能屬性
2009年1月7日 星期三
在GridView,針對Button的設定
使用GridView時,針對Button的設定,如果只需一個參數就好解決,但遇到要多個參數就有點麻煩了,經過這段時間的磨練,有兩種方式可以設定,紀錄一下
第一種
.aspx
GridView
< id="btn_Delete" runat="server" text="刪除" onclick="Del_Click">
.cs
GridView_RowDataBound
if (e.Row.RowType == DataControlRowType.DataRow)
Button btn_Delete = (Button)e.Row.FindControl("btn_Delete"); btn_Delete.Attributes.Add("OnClick", "if (confirm('您確定要刪除嗎?')==false) {return false;}");
btn_Delete.Attributes["id"] = DataBinder.Eval(e.Row.DataItem, "id").ToString();
btn_Delete.Attributes["sn"] = DataBinder.Eval(e.Row.DataItem, "sn").ToString();
protected void Del__Click(object sender, EventArgs e)
{
Button btnDel = (Button)sender;
string id= btnDel.Attributes["id"].ToString();
string sn= btnDel.Attributes["sn"].ToString();
//其他作業
}
第二種
.cs
GridView_RowDataBound
if (e.Row.RowType == DataControlRowType.DataRow)
Button btn_Delete = (Button)e.Row.FindControl("btn_Delete");
btn_addsub.CommandName = "Delete";
btn_addsub.CommandArgument = string.Format("{0},{1}", DataBinder.Eval(e.Row.DataItem, "id"), DataBinder.Eval(e.Row.DataItem, "sn"));
GridView_RowCommand
switch (e.CommandName)
{
case "Delete":
string[] aString = Convert.ToString(e.CommandArgument).Split(',');
btnDelete(aString[0], aString[1]);
break;
}
private void btnDelete(string id, string sn)
{
}
第一種
.aspx
GridView
< id="btn_Delete" runat="server" text="刪除" onclick="Del_Click">
.cs
GridView_RowDataBound
if (e.Row.RowType == DataControlRowType.DataRow)
Button btn_Delete = (Button)e.Row.FindControl("btn_Delete"); btn_Delete.Attributes.Add("OnClick", "if (confirm('您確定要刪除嗎?')==false) {return false;}");
btn_Delete.Attributes["id"] = DataBinder.Eval(e.Row.DataItem, "id").ToString();
btn_Delete.Attributes["sn"] = DataBinder.Eval(e.Row.DataItem, "sn").ToString();
protected void Del__Click(object sender, EventArgs e)
{
Button btnDel = (Button)sender;
string id= btnDel.Attributes["id"].ToString();
string sn= btnDel.Attributes["sn"].ToString();
//其他作業
}
第二種
.cs
GridView_RowDataBound
if (e.Row.RowType == DataControlRowType.DataRow)
Button btn_Delete = (Button)e.Row.FindControl("btn_Delete");
btn_addsub.CommandName = "Delete";
btn_addsub.CommandArgument = string.Format("{0},{1}", DataBinder.Eval(e.Row.DataItem, "id"), DataBinder.Eval(e.Row.DataItem, "sn"));
GridView_RowCommand
switch (e.CommandName)
{
case "Delete":
string[] aString = Convert.ToString(e.CommandArgument).Split(',');
btnDelete(aString[0], aString[1]);
break;
}
private void btnDelete(string id, string sn)
{
}
網頁也可有訊問方塊MessageBox:Yes No
建立:兩個Button:「是」,「否」
程式碼:
protected void btn_Y_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "select", string.Format("returnValue='{0}';window.close();", "Yes"), true);
}
protected void btn_N_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "select", string.Format("returnValue='{0}';window.close();", "No"), true);
}
呼叫的頁面
.aspx
javascript
function doIsSave()
{
var url = 'Messagebox.aspx';
var retValue = window.showModalDialog(url, '提示', 'resizable:no;scroll:no;status:no;dialogHeight=80pt;dialogWidth=300pt');
if(retValue != null && retValue !="")
{ //alert(retValue);
document.getElementById("h_issave").value=retValue;
}
}

程式碼:
protected void btn_Y_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "select", string.Format("returnValue='{0}';window.close();", "Yes"), true);
}
protected void btn_N_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "select", string.Format("returnValue='{0}';window.close();", "No"), true);
}
呼叫的頁面
.aspx
javascript
function doIsSave()
{
var url = 'Messagebox.aspx';
var retValue = window.showModalDialog(url, '提示', 'resizable:no;scroll:no;status:no;dialogHeight=80pt;dialogWidth=300pt');
if(retValue != null && retValue !="")
{ //alert(retValue);
document.getElementById("h_issave").value=retValue;
}
}

.cs
page_Load:Button.Attributes.Add("OnClick", "javascript:doIsSave();");
protected void Button_Click(object sender, EventArgs e)
{
if (h_issave.Value == "Yes")
if (h_issave.Value == "No")
}
2008年12月25日 星期四
在GridView,每筆資料的CheckBox只能單選的用法
樣式:
程式設定:
protected void gv_major_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//當勾選「完成」,就對「未完成」進行checked=false;
ckb_finish.Attributes["onclick"] = string.Format(@"uncheck('{0}');", ckb_nofinish.ClientID);
ckb_nofinish.Attributes["onclick"] = string.Format(@"uncheck('{0}');", ckb_finish.ClientID);
}
}
javascript
function uncheck(id)
{
var obj = document.getElementById(id);
obj.checked = false;
}

程式設定:
protected void gv_major_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//當勾選「完成」,就對「未完成」進行checked=false;
ckb_finish.Attributes["onclick"] = string.Format(@"uncheck('{0}');", ckb_nofinish.ClientID);
ckb_nofinish.Attributes["onclick"] = string.Format(@"uncheck('{0}');", ckb_finish.ClientID);
}
}
javascript
function uncheck(id)
{
var obj = document.getElementById(id);
obj.checked = false;
}
感謝Lillian指導
2008年12月1日 星期一
DataSet讀取XML字串
DataSet dataSet = new DataSet();
System.IO.StringReader reader = new System.IO.StringReader(xml格式字串);
dataSet.ReadXml(reader);
參考來源:http://blog.csdn.net/daniao2003/archive/2007/08/04/1725857.aspx
System.IO.StringReader reader = new System.IO.StringReader(xml格式字串);
dataSet.ReadXml(reader);
參考來源:http://blog.csdn.net/daniao2003/archive/2007/08/04/1725857.aspx
2008年11月23日 星期日
用charindex來過濾欄位資料是串聯格式
語法
CHARINDEX ( expression1 ,expression2 [ , start_location ] )
EX:
欄位資料是123,2222
select * from Table Where (CHARINDEX(對象Field,資料來源)=0)
註:
=0:不存在於資料來源中,像 not in
>0:存在於資料來源中,像 in
CHARINDEX ( expression1 ,expression2 [ , start_location ] )
EX:
欄位資料是123,2222
select * from Table Where (CHARINDEX(對象Field,資料來源)=0)
註:
=0:不存在於資料來源中,像 not in
>0:存在於資料來源中,像 in
訂閱:
文章 (Atom)