asp.net 값 전달 요약

怪我咯
풀어 주다: 2017-03-31 11:48:17
원래의
1731명이 탐색했습니다.

기사는 대부분 asp.net2.0에 적합하다고 읽었습니다
1. 새 창을 열고 매개변수 보내기:
매개변수 보내기:
response.write ( "<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="++"')</script>")
수신 매개변수:
문자열 a = Request.QueryString["id"];
string b = Request.QueryString["id1"];

2. 버튼
Button1.Attributes.Add( "onclick" ,"return verify('confirm?')");
button.attributes.add("onclick","if(confirm('확실합니까?')){return true;}else{return false;} ")

3. 테이블에서 선택한 레코드 삭제
int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex];
string deleteCmd = "DELETE from Employee where emp_id = " + intEmpID.ToString()

4. 테이블 레코드 삭제 경고

private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e)
{
switch(e.Item. ItemType)
{
case ListItemType.Item :
case ListItemType.AlternatingItem :
case ListItemType.EditItem:
TableCell myTableCell;
myTableCell = e.Item.Cells[14];
LinkButton myDeleteButton ;
myDeleteButton = (LinkButton)myTableCell.Controls[0];
myDeleteButton.Attributes.Add
("onclick","return verify('이 항목을 삭제하시겠습니까? message');" );
break;
default:
break;
}

}

5. 다른 페이지로 연결하려면 표 행을 클릭하세요.

private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//열 테이블을 클릭하세요
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
e.Item.Attributes.Add("onclick","window.open('Default.aspx?id=" + e.Item.Cells [0].Text + "') ;");
}

itemDataBind 이벤트에서 테이블을 두 번 클릭하여 다른 페이지에 연결합니다.
if(e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
string OrderItemID =e.item.cells[1].Text;
e.item.Attributes.Add("ondblclick ","location.href='../ShippedGrid .aspx?id=" + OrderItemID + "'");
}

새 페이지를 열려면 표를 두 번 클릭
하세요. (e.Item.ItemType == ListItemType.Item ||e.Item .ItemType == ListItemType.AlternatingItem)
{
string OrderItemID =e.item.cells[1].Text;
e. item.Attributes.Add("ondblclick", "open('.. /ShippedGrid.aspx?id=" + OrderItemID + "')");
}

★특별 참고 사항: [?id =]는 [?id =]
6일 수 없습니다. 매개변수를 전달하는 테이블 하이퍼링크 열
NavigateUrl="aaa .aspx?id='<%# DataBinder.Eval( Container.DataItem, "데이터 필드 1")%>'
& name='<%# DataBinder.Eval(Container.DataItem, "데이터 필드 2")%>' />

7. 색상을 변경하려면 표를 클릭하세요
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add ("onclick","this.style.BackgroundColor='#99cc00';
this.style.color='buttontext';this. style.cursor='default';");
}

DataGrid의 _ItemDataBound에 쓰기
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes .Add("onmouseover","this.style.BackgroundColor='#99cc00';
this.style.color='buttontext';this. style.cursor='default';");
e.Item.Attributes.Add("onmouseout","this.style.BackgroundColor='';this.style.color='';");
}

8. 날짜 형식에 대해
날짜 형식 설정

DataformatString="{0:yyyy-MM-dd}"
itembound 이벤트에 있어야 할 것 같아요
e.items.cell["귀하의 열"].text =DateTime.Parse(e.items.cell["귀하의 열"].text.ToString("yyyy-MM-dd"))

9. 오류 메시지를 받고 지정된 페이지로 이동
 Server.Transfer 대신 Response.Redirect를 사용하지 마세요
 e.g

// in global.asax
protected void Application_Error(Object sender, EventArgs e) {
if (Server.GetLastError( ) is HttpUnhandledException)
Server.Transfer("MyErrorPage.aspx");

//나머지는 그대로 둡니다. -ASP.NET에 대한 HttpUnhandledException 예외 및 괜찮습니다
}

Redirect로 인해 포스트백이 생성되고 오류 정보가 손실되므로 페이지 안내는 서버 측에서 직접 실행되어야 하므로 오류 처리 페이지에서 오류 정보를 확인하고 그에 따라 처리할 수 있습니다.

10. 쿠키 지우기

Cookie.Expires=[DateTime];
Response.Cookies("UserName") .Expires = 0
11. 사용자 정의 예외 처리

//사용자 정의 예외 처리 클래스
using System;
using System.Diagnostics;

네임스페이스 MyAppException
{
/**////


/// 시스템 예외 클래스 ApplicationException에서 상속된 응용 프로그램 예외 처리 클래스입니다.
/// Windows NT/2000의 응용 프로그램 로그에 예외 내용을 자동으로 기록합니다
///

public class AppException:System.ApplicationException
{
public AppException( )
{
if (ApplicationConfiguration.EventLogEnabled)
LogEvent("알 수 없는 오류가 발생했습니다.");
}

public AppException(문자열 메시지)
{
LogEvent(message);
}

public AppException(string message,Exception innerException)
{
LogEvent(message);
if (innerException != null)
{
LogEvent(innerException.Message);
}
}

//Logging 클래스
using System;
using System.Configuration;
system .Diagnostics 사용 ;
System.IO 사용;
System.Text 사용;
System.Threading 사용;

네임스페이스 MyEventLog
{
/**//// /// 이벤트 로깅 클래스, 이벤트 로깅 지원 제공
///
/// 4가지 로깅 방법 정의(오류, 경고, 정보, 추적)
/// < ;/remarks>
///
public class ApplicationLog
{
/**////
/// Win2000/NT 이벤트 로그에 오류 정보 기록
/// 기록할 텍스트 정보 ///

public static void WriteError(String message)
{

WriteLog(TraceLevel.Error, message);
}

/ **////
/// 기록 Win2000/NT 이벤트 로그에 경고 정보
/// 기록할 텍스트 정보
/// < /summary>
public static void WriteWarning(문자열 메시지)
{

WriteLog(TraceLevel.Warning, 메시지);
}

/**////
/// Win2000/NT 이벤트 로그에 프롬프트 정보를 기록합니다
/// 기록할 텍스트 정보 ///

public static void WriteInfo(String message)
{
WriteLog(TraceLevel.Info, message);
}
/** ////
/// Win2000/NT 이벤트 로그에 추적 정보 기록
/// 기록할 텍스트 정보 /// public static void WriteTrace(String message)
{

WriteLog(TraceLevel.Verbose, message);
}
/ **////
/// 이벤트 로그에 기록되는 텍스트 정보 형식을 포맷합니다.
/// 포맷이 필요한 예외 객체 ;
/// 예외 정보 제목 문자열.
///
/// After format Exception 예외 콘텐츠 및 추적 스택을 포함한 정보 문자열.
///

///

public static String formatException(Exception ex , String catchInfo )
{
StringBuilder strBuilder = new StringBuilder();
if (catchInfo != String.Empty)
{
strBuilder.Append(catchInfo).Append("/r /n" );
}
strBuilder.Append(ex.Message).Append("/r/n").Append(ex.StackTrace);
return strBuilder.ToString();
}

/**//// < ;summary>
/// 실제 이벤트 로그 작성 방법
/// 기록할 정보의 수준(오류, 경고, 정보, 추적).
/// 기록할 텍스트입니다.
///

private static void WriteLog(TraceLevel level , String messageText)
{

try
{
EventLogEntryType LogEntryType;
스위치(레벨)
{
case TraceLevel .Error:
LogEntryType = EventLogEntryType .Error;
break;
케이스 TraceLevel.Warning:
LogEntryType = EventLogEntryType.Warning;
break;
케이스 TraceLevel.Info:
LogEntryType = EventLogEntryType.Information;
break;
케이스 TraceLevel.Verbose:
LogEntryType = EventLogEntryType.SuccessAudit;
break;
기본값:
LogEntryType = EventLogEntryType.SuccessAudit dit;
break;
}

EventLog eventLog = new EventLog("Application", ApplicationConfiguration.EventLogMachineName, ApplicationConfiguration.EventLogSourceName );
//이벤트 로그 쓰기
eventLog.WriteEntry(messageText, LogEntryType ; >


13. 탭으로 변환하려면 Enter를 누르세요. >


onkeydown="if(event.keyCode==13) event.keyCode=9"

http://dotnet. aspx .cc/exam/enter2tab.aspx

14.DataGrid 슈퍼 연결 열

DataNavigateUrlField="필드 이름" DataNavigateUrlformatString="http://xx/inc/delete.aspx?ID= { 0}"

15.DataGrid 행은 마우스로 색상을 변경합니다

private void DGzf_ItemDataBound
(객체 전송자, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType!=ListItemType.Header)
{
e.Item.Attributes.Add( "onmouseout","this.style.BackgroundColor=
/""+e .Item.style["BACKGROUND-COLOR"]+"/"");
e.Item.Attributes.Add( "onmouseover","this.style.BackgroundColor=/""+ "#EFF3F7"+" /"" );
}
}

16. 템플릿 열










< /ITEMTEMPLATE>





백엔드 코드

protected void CheckAll_CheckedChanged(object sender, System.EventArgs e)
{
//모든 항목을 달성하려면 열 선택을 변경하세요. 또는 모두 선택하지 마십시오.
CheckBox chkExport; );
chkExport.Checked = true;
}
}
else
{
foreach(DataGridItem oDataGridItem in MyDataGrid.Items)
{
chkExport = (CheckBox )oDataGridItem.FindControl("chkExport");
chkExport.Checked = false;
}
}
}
17. 숫자 형식 지정

【<%# Container.DataItem("price")%>의 결과는 500.000입니다. 500.00으로 형식을 지정하는 방법은 무엇입니까?】
<%#Container.DataItem("price","{0:\ #,##0.00}" )%>
int i=123456;
string s=i.ToString("###,###.00");

18. 날짜 형식

[aspx 페이지에서: <%# DataBinder.Eval(Container.DataItem, "Company_Ureg_Date")%>
은 다음과 같이 표시됩니다: 2004-8-11 19:44:28
그냥 원하는 날짜: 2004-8-11 】

<%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date","{0:yyyy-M-d}")%>

어떻게 바꾸나요?

【날짜 형식】
꺼내서 보통 객체
((DateTime)objectFromDB).ToString("yyyy-MM-dd");

【날짜 검증 표현식 ]
A. 다음 올바른 입력 형식: [2004-02-29], [2004-02-29 10:29:39 pm], [2004/12/31]

^((/d{2 }(([02468][048])|([13579][26]))[/-///s]?((((0?[13578])|(1[02]))
[/-///초]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469] )|(11))[/-///s]?((0?[1-9])|
([1-2][0-9])|(30)))|(0 ?2[/-///초]?((0?[1-9])|([1-2][0-9])))))|(/d{2}(([02468]
[1235679])|([13579][01345789]))[/-///s]?((((0?[13578])|(1[02]))[/-/// s]
?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|( 11))[/-///s]?((0?[1-9])|
([1-2][0-9])|(30)))|(0?2[ /-///s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))
(/s((( 0?[1-9])|(1[0-2]))/:([0-5][0-9])((/초)|(/:([0-5][0- 9])/s))
([AM|PM|am|pm]{2,2})))?$

B. 올바른 입력 형식: [0001-12-31 ], [9999 09 30], [2002/03/03]

^/d{4}[/-///s]?((((0[13578])|(1[02 ]))[/-///s]?(([0-2][0-9])|(3[01])))|
(((0[469])|(11) )[/-///초]?(([0-2][0-9])|(30)))|(02[/-///초]?[0-2][0-9 ]))$

[대소문자 변환]

HttpUtility.HtmlEncode(string);
HttpUtility.HtmlDecode(string)

19. 🎜>
in Global.asax
in Application_Start() 이벤트
Add Application[속성 이름] = xxx;
전역 변수입니다

20. HyperLinkColumn을 만드는 방법 연결이 생성되면 연결을 클릭하여 새 창을 열까요?

HyperLinkColumn에는 Target 속성이 있습니다. 값을 "_blank"로 설정하세요. (Target="_blank")

[ASPNETMENU] 메뉴 항목을 클릭하면 새 창이 열립니다.
menuData.xml 파일의 메뉴 항목에 URLTarget="_blank"
를 추가합니다. 예:






URLTarget="_blank" LeftIcon="file.gif"/>


aspnetmenu를 버전 1.2로 업그레이드하는 것이 가장 좋습니다


위 내용은 asp.net 값 전달 요약의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!