마스터 페이지 (내 템플릿 페이지)를 만들고 그 위에 gridview를 배치합니다. 이제이 마스터 페이지를 사용할 다중 페이지 (aspx)를 생성합니다. 이러한 aspx 페이지에 대한 모든 설정을 수행하는 대신 데이터 소스를 구성하기 만하면됩니다. aspx가로드되면 데이터 소스가 gridview (마스터 페이지에 있음)에 연결되고로드됩니다. 이제 gridview 내부의 데이터를 조작하고 싶지만 데이터 키 개수가 0을 반환하고 있습니다. 예를 들어 gv.Rows(dr.RowIndex).Cells(5)
을 통해 값에 액세스 할 수 있습니다. 그러나 나는 데이터 키를 통해 그것을하고 싶다. 내 코드는 아래에, 어떤 도움을 주셔서 감사합니다. 감사.0을 반환하는 Datakeys 개수
Public Sub ConnectDataSource()
Dim mpContentPlaceHolder As ContentPlaceHolder
Dim gv As GridView
mpContentPlaceHolder = CType(Master.FindControl("GridViewPlaceHolder"), ContentPlaceHolder)
If Not mpContentPlaceHolder Is Nothing Then
gv = CType(mpContentPlaceHolder.FindControl("GridView1"), GridView)
If Not gv Is Nothing Then
Dim es As EntityDataSource = EntityDataSource1
gv.DataSource = es
gv.DataBind()
Debug.WriteLine("datakey count " + gv.DataKeys().Count.ToString())
' gv.HeaderRow.Cells(2).Text = "sdfds" // to change header text for each column.
End If
End If
End Sub
Private Sub PaymentRules_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim toolbarPlaceHolder As ContentPlaceHolder
Dim btn As ImageButton
toolbarPlaceHolder = CType(Master.FindControl("ToolBarPlaceHolder"), ContentPlaceHolder)
If Not toolbarPlaceHolder Is Nothing Then
btn = DirectCast(toolbarPlaceHolder.FindControl("ImageButton2"), ImageButton)
If Not btn Is Nothing Then
AddHandler btn.Click, AddressOf ImageButton2_Click
End If
End If
If (Not Page.IsPostBack) Then
ConnectDataSource()
End If
End Sub
Protected Sub ImageButton2_Click(sender As Object, e As EventArgs)
Debug.WriteLine("ImageButton2_Click")
Dim maList As New List(Of Integer)
Dim mContentPlaceHolder As ContentPlaceHolder
Dim gv As GridView
mContentPlaceHolder = CType(Master.FindControl("GridViewPlaceHolder"), ContentPlaceHolder)
If Not mContentPlaceHolder Is Nothing Then
gv = CType(mContentPlaceHolder.FindControl("GridView1"), GridView)
If Not gv Is Nothing Then
For Each dr As GridViewRow In gv.Rows
If ((TryCast(dr.FindControl("CheckBox1"), CheckBox)).Checked = True) Then
'Debug.WriteLine(dr.RowIndex.ToString())
'Dim id As Integer = gv.DataKeys(dr.RowIndex).Value
'maList.Add(id)
Debug.WriteLine("row index " + gv.Rows(dr.RowIndex).Cells(5).Text)
Debug.WriteLine("datakey count " + gv.DataKeys().Count.ToString())
End If
Next
End If
End If
End Sub
수정 됨 - 마스터 페이지 코드
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="JSPSite.master.vb" Inherits="SSPayroll.JSPSite" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<link href="../Styles/Style1.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="Form1" runat="server">
<div class="page">
<div class="header">
<div class="title">
<h1>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/GSCV1.01 - Copy.png"
Height="73px" style="margin-top: 20px" Width="428px" />
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<LoggedInTemplate>
<asp:Label ID="Label2" runat="server" Text="User: " Font-Names="Cambria"></asp:Label><span class="bold">
<asp:LoginName ID="HeadLoginName" runat="server" Font-Names="Cambria" />
</span> [
<asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect"
LogoutPageUrl="~/" Font-Names="Cambria" Font-Size="Small" ForeColor="#D9D5D5" Font-Bold="True" LogoutText="Sign Out" />
]
<div>
</div>
</LoggedInTemplate>
<RoleGroups>
<asp:RoleGroup>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
<asp:Label ID="Label1" runat="server" Text="Date/Time" Font-Names="Cambria"
Font-Size="Small" ForeColor="#333333"></asp:Label>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="False"
IncludeStyleBlock="False" Orientation="Horizontal" BackColor="#FFFBD6"
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em"
ForeColor="#990000" StaticSubMenuIndent="10px" Enabled="True">
<DynamicHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#FFFBD6" />
<DynamicSelectedStyle BackColor="#FFCC66" />
<Items>
<asp:MenuItem Text="Menu1" Value="Tools">
<asp:MenuItem NavigateUrl="~/JSPayroll/Payment_Rules/PaymentRules.aspx" Text="Payment Rules" Value="Payment Rules"></asp:MenuItem>
</asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#990000" ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#FFCC66" />
</asp:Menu>
</div>
</div>
<asp:ContentPlaceHolder ID="ToolBarPlaceHolder" runat="server" >
<asp:Panel ID="Panel1" runat="server" HorizontalAlign="Center">
<div>
<hr />
<asp:ImageButton ID="ImageButton1" runat="server" Height="48px" ImageUrl="~/IconsPack/Home.png" Width="48px" ToolTip="Home" CssClass="morph" />
<asp:ImageButton ID="ImageButton2" runat="server" Height="48px" ImageUrl="~/IconsPack/Add.png" ToolTip="Add Record" CssClass="morph" Width="48px"/>
<asp:ImageButton ID="ImageButton3" runat="server" Height="48px" ImageUrl="~/IconsPack/Edit E.png" ToolTip="Edit Record" CssClass="morph" Width="48px" />
<asp:ImageButton ID="ImageButton4" runat="server" Height="48px" ImageUrl="~/IconsPack/ViewDetails.png" ToolTip="View Record Details" CssClass="morph" Width="48px" />
<asp:ImageButton ID="ImageButton5" runat="server" Height="48px" ImageUrl="~/IconsPack/Delete.png" ToolTip="Delete Record" CssClass="morph" Width="48px" />
<asp:ImageButton ID="ImageButton6" runat="server" Height="48px" ImageUrl="~/IconsPack/Approved.png" ToolTip="Approve Record" CssClass="morph" Width="48px"/>
<asp:ImageButton ID="ImageButton7" runat="server" Height="48px" ImageUrl="~/IconsPack/Denied.png" ToolTip="Unapprove Record" CssClass="morph" Width="48px"/>
<asp:ImageButton ID="ImageButton8" runat="server" Height="48px" ImageUrl="~/IconsPack/Update.png" ToolTip="Refresh Table" CssClass="morph" Width="48px"/>
<hr />
</div>
</asp:Panel>
</asp:ContentPlaceHolder>
<%--<asp:ContentPlaceHolder ID="GridViewPlaceHolder" runat="server">--%>
<div class="EU_TableScroll" id="showData" style="display: block">
<asp:GridView ID="GridView1" runat="server" CssClass="EU_DataTable" EmptyDataText="No Data Available.">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<%--</asp:ContentPlaceHolder>--%>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
</body>
</html>
왜 이렇게 확장해야합니까? –
나는 그것을 꺼내었고 여전히 0을 반환합니다! –
공유 aspx 코드 –