RowDataBound 이벤트는 서버 측에서 처리됩니다. "코드 숨김"파일에 이벤트 코드/논리가 있거나 HTML 파일에 인라인 스크립트를 추가 할 수 있습니다.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// logic here
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>GridView RowDataBound Event</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">GridView OnRowDataBound</h2>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT ProductID, ProductName, UnitPrice FROM Products"
>
</asp:SqlDataSource>
<asp:GridView
ID="GridView1"
runat="server"
DataSourceID="SqlDataSource1"
ForeColor="AliceBlue"
BackColor="DarkSalmon"
BorderColor="Salmon"
HeaderStyle-BackColor="Crimson"
AllowPaging="true"
AutoGenerateColumns="true"
DataKeyNames="ProductID"
OnRowDataBound="GridView1_RowDataBound"
>
</asp:GridView>
</div>
</form>
</body>
OnRowDataBound 속성은 even 메서드와 동일한 이름이어야합니다. 예를 들어 OnRowDataBound="GridView1_RowDataBound"
의 이름은 이벤트 처리기 서명 GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
과 같습니다.
자세한 내용은 here을 참조하십시오.
감사합니다. 또한 나는 서버 측에서 다른 모든 C# 파일이있는 디렉토리에 "App_Code"라는 폴더가 있다고 언급하고 싶습니다. 또한 새 C# 파일을 만들고 행 이벤트/함수를 배치하고 default.aspx에 GridView를 링크 할 수 있습니까? – charlie
네가 그렇게 할 수 있다고 믿는다. .aspx 파일 내에서 src 경로를 업데이트하려고합니다. <% @ Page .. src = "CodeBehind.cs"%> –