На самом деле я разрабатываю шаблон с использованием ASP.net и C #.
как вы можете видеть на картинке ниже, мой шаблон включает в себя 3 части, и я хочу, чтобы у меня было частичное обновление, поэтому я использую панель обновления.
в этом шаблоне, когда пользователь нажимает на верхнее меню, он обновляет боковое меню, затем, когда пользователь нажимает на боковое меню, он обновляет среднюю страницу контента.
Я использую мастер-страницу в этом сценарии, потому что я собираюсь загрузить страницу ASPX на средней странице контента. основываясь на моем коде, нормальная страница легко загружается в этой части, но когда я хочу загрузить страницу, которая включает просмотр списка:
<%@ Page Title="" Language="C#" MasterPageFile="~/MainMasterPage.master" AutoEventWireup="true" CodeFile="ContentPage1.aspx.cs" Inherits="ContentPage1" %>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server" Visible="true">
<asp:Panel ID="ContentPanel" runat="server" Visible="true">
<fieldset style=" height:350px;">
<legend>Details</legend>
<asp:Label ID="TestLable" runat="server" Text="This is a test"></asp:Label>
<!--------- ListView Block --------->
<asp:ListView ID="lvEmployee" runat="server"
onitemediting="lvEmployee_ItemEditing"
onitemupdating="lvEmployee_ItemUpdating"
onitemcanceling="lvEmployee_ItemCanceling"
onitemdeleting="lvEmployee_ItemDeleting"
InsertItemPosition="LastItem"
OnSorting="lvEmployee_Sorting"
oniteminserting="lvEmployee_ItemInserting"
DataKeyNames="EmpID" >
<LayoutTemplate>
<!---- Layout Template: is the place to design the form layout ---->
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="1" style="background-color: #DCDCDC;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">
</th>
<th id="Th2" runat="server">
EmpID
<asp:ImageButton ID="imEmpID" CommandArgument="EmpID" CommandName="Sort" ImageUrl="~/img/asc.png" runat="server" />
</th>
<th id="Th3" runat="server">
EmpName
<asp:ImageButton ID="imEmpName" CommandArgument="EmpName" CommandName="Sort" ImageUrl="~/img/asc.png" runat="server" />
</th>
<th id="Th4" runat="server">
Department
</th>
<th id="Th5" runat="server">
Age
</th>
<th id="Th6" runat="server">
Address
</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style="text-align: center;background-color: #CCCCCC;">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="You received the following errors:" ShowMessageBox="true" ShowSummary="false" ValidationGroup="VGEditTmp" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" HeaderText="You received the following errors:" ShowMessageBox="true" ShowSummary="false" ValidationGroup="VGInsertTmp" />
</td>
</tr>
</table>
<br />
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="lvEmployee" PageSize="5" onprerender="DataPager1_PreRender">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="true" ShowLastPageButton="true"/>
<asp:TemplatePagerField>
<PagerTemplate>
<span style="color:Maroon;">Records:
<%# Container.StartRowIndex >= 0 ? (Container.StartRowIndex + 1) : 0 %>
-
<%# (Container.StartRowIndex + Container.PageSize) > Container.TotalRowCount ? Container.TotalRowCount : (Container.StartRowIndex + Container.PageSize)%>
of
<%# Container.TotalRowCount %>
<span style="color:Red;">
OR
</span>
<span style="color: Blue;">
Page
<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>
of
<%# Math.Ceiling((double)Container.TotalRowCount / Container.PageSize) %>
</span>
</span>
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<!---- Item Template: is the place to design how to show the items inside the form ---->
<tr style="background-color:#FFF8DC;color: #000000;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" CausesValidation="false" OnClientClick="return confirm('Are you sure you want to delete this Employee Details?');" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" CausesValidation="false" />
</td>
<td>
<asp:Label ID="EmpIDLabel" runat="server" Text='<%# Eval("EmpID") %>' />
</td>
<td>
<asp:Label ID="EmpNameLabel" runat="server" Text='<%# Eval("EmpName") %>' />
</td>
<td>
<asp:Label ID="DepartmentLabel" runat="server" Text='<%# Eval("Department") %>' />
</td>
<td>
<asp:Label ID="AgeLabel" runat="server" Text='<%# Eval("Age") %>' />
</td>
<td>
<asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("Address") %>' />
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<!---- Edit Item Template: is the place to design the edit form ---->
<tr style="background-color:#008A8C;color: #FFFFFF;">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" ValidationGroup="VGEditTmp" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
</td>
<td>
<asp:Label ID="EmpIDLabel1" runat="server" Text='<%# Eval("EmpID") %>' />
</td>
<td>
<asp:TextBox ID="EmpNameTextBox" runat="server" Text='<%# Bind("EmpName") %>' ValidationGroup="VGEditTmp" />
<asp:RequiredFieldValidator runat="server" ID="RequiredName" ControlToValidate="EmpNameTextBox" ErrorMessage="Name is required" ValidationGroup="VGEditTmp" Display="None" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regName" runat="server" ControlToValidate="EmpNameTextBox" ValidationExpression="^[a-zA-Z'.\s]{1,50}" ErrorMessage="Enter a valid Name" ValidationGroup="VGEditTmp" Display="None"></asp:RegularExpressionValidator>
</td>
<td>
<asp:TextBox ID="DepartmentTextBox" runat="server" Text='<%# Bind("Department") %>' />
</td>
<td>
<asp:TextBox ID="AgeTextBox" runat="server" Text='<%# Bind("Age") %>' ValidationGroup="VGEditTmp" />
<asp:RangeValidator ID="ValidateAge" runat="server" ControlToValidate="AgeTextBox" MinimumValue="18" MaximumValue="50" Type="Integer" ErrorMessage="Age should be within the valid interval" ValidationGroup="VGEditTmp" SetFocusOnError="true" Display="None"></asp:RangeValidator>
</td>
<td>
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
</td>
</tr>
</EditItemTemplate>
<InsertItemTemplate>
<!---- Insert Item Template: is the place to design the insert form ---->
<tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" ValidationGroup="VGInsertTmp" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" CausesValidation="false" />
</td>
<td>
</td>
<td>
<asp:TextBox ID="EmpNameTextBox" runat="server" Text='<%# Bind("EmpName") %>' ValidationGroup="VGInsertTmp" />
<asp:RequiredFieldValidator runat="server" ID="RequiredName" ControlToValidate="EmpNameTextBox" ErrorMessage="Name is required" ValidationGroup="VGInsertTmp" Display="None"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regName" runat="server" ControlToValidate="EmpNameTextBox" ValidationExpression="^[a-zA-Z'.\s]{1,50}" ErrorMessage="Enter a valid Name" ValidationGroup="VGInsertTmp" Display="None"></asp:RegularExpressionValidator>
</td>
<td>
<asp:TextBox ID="DepartmentTextBox" runat="server" Text='<%# Bind("Department") %>' />
</td>
<td>
<asp:TextBox ID="AgeTextBox" runat="server" Text='<%# Bind("Age") %>' ValidationGroup="VGInsertTmp" />
<asp:RangeValidator ID="ValidateAge" runat="server" ControlToValidate="AgeTextBox" MinimumValue="18" MaximumValue="50" Type="Integer" ErrorMessage="Age should be within the valid interval" ValidationGroup="VGInsertTmp" SetFocusOnError="true" Display="None"></asp:RangeValidator>
</td>
<td>
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<asp:HiddenField ID="hid_UpdateQT" Value="" runat="server" />
<asp:HiddenField ID="hid_SortExpression" Value="" runat="server" />
</fieldset>
</asp:Panel>
</asp:Content>
это не показывает страницу. мой код за этой страницей списка выглядит так:
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
BindLV("");
}
}
public DataTable GetEmployee(string query)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
SqlDataAdapter ada = new SqlDataAdapter(query, con);
DataTable dtEmp = new DataTable();
ada.Fill(dtEmp);
return dtEmp;
}
private void BindLV(string SortExpression)
{
string UpdateQuery = "Select * from Employee" + SortExpression;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
hid_UpdateQT.Value = UpdateQuery;
lvEmployee.Items.Clear();
lvEmployee.DataSource = GetEmployee(UpdateQuery);
lvEmployee.DataBind();
}
protected void lvEmployee_Sorting(object sender, ListViewSortEventArgs e)
{
ImageButton imEmpID = lvEmployee.FindControl("imEmpID") as ImageButton;
ImageButton imEmpName = lvEmployee.FindControl("imEmpName") as ImageButton;
string DefaultSortIMG = "~/img/asc.png";
string imgUrl = "~/img/desc.png";
string sortExpression = hid_SortExpression.Value;
if (!"".Equals(sortExpression))
{
if (e.SortExpression.Equals(sortExpression))
{
hid_SortExpression.Value = "";
sortExpression = "";
imgUrl = DefaultSortIMG;
}
else
{
hid_SortExpression.Value = e.SortExpression;
sortExpression = e.SortExpression;
}
}
else
{
hid_SortExpression.Value = e.SortExpression;
sortExpression = e.SortExpression;
}
switch (e.SortExpression)
{
case "EmpID":
if (imEmpName != null)
imEmpName.ImageUrl = DefaultSortIMG;
if (imEmpID != null)
imEmpID.ImageUrl = imgUrl;
break;
case "EmpName":
if (imEmpID != null)
imEmpID.ImageUrl = DefaultSortIMG;
if (imEmpName != null)
imEmpName.ImageUrl = imgUrl;
break;
}
BindLV(" order by " + e.SortExpression + " " + (!"".Equals(sortExpression) ? "ASC" : "DESC"));
}
protected void DataPager1_PreRender(object sender, EventArgs e)
{
//string strtmp = Request.Params["hid_UpdateQT"];
string strtmp = hid_UpdateQT.Value;
if (null == strtmp || "".Equals(strtmp))
{
strtmp = "Select * from Employee";
}
lvEmployee.DataSource = GetEmployee(strtmp);
lvEmployee.DataBind();
}
protected void lvEmployee_ItemEditing(object sender, ListViewEditEventArgs e)
{
lvEmployee.EditIndex = e.NewEditIndex;
}
protected void lvEmployee_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
string empid = "", name = "", dept = "", age = "", address = "";
Label lbl = (lvEmployee.Items[e.ItemIndex].FindControl("EmpIDLabel1")) as Label;
if (lbl != null)
empid = lbl.Text;
TextBox txt = (lvEmployee.Items[e.ItemIndex].FindControl("EmpNameTextBox")) as TextBox;
if (txt != null)
name = txt.Text;
txt = (lvEmployee.Items[e.ItemIndex].FindControl("DepartmentTextBox")) as TextBox;
if (txt != null)
dept = txt.Text;
txt = (lvEmployee.Items[e.ItemIndex].FindControl("AgeTextBox")) as TextBox;
if (txt != null)
age = txt.Text;
txt = (lvEmployee.Items[e.ItemIndex].FindControl("AddressTextBox")) as TextBox;
if (txt != null)
address = txt.Text;
string UpdateQuery = "UPDATE [Employee] SET [EmpName] = '" + name + "', [Department] = '" + dept + "', [Age] = '" + age + "', [Address] = '" + address + "' WHERE [EmpID] = '" + empid + "'";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand(UpdateQuery, con);
com.ExecuteNonQuery();
con.Close();
lvEmployee.DataSource = GetEmployee("Select * from Employee");
lvEmployee.DataBind();
lvEmployee.EditIndex = -1;
}
protected void lvEmployee_ItemCanceling(object sender, ListViewCancelEventArgs e)
{
lvEmployee.EditIndex = -1;
}
protected void lvEmployee_ItemDeleting(object sender, ListViewDeleteEventArgs e)
{
string empid = "";
Label lbl = (lvEmployee.Items[e.ItemIndex].FindControl("EmpIDLabel")) as Label;
if (lbl != null)
empid = lbl.Text;
string DeleteQuery = "Delete from Employee WHERE [EmpID] = '" + empid + "'";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand(DeleteQuery, con);
com.ExecuteNonQuery();
con.Close();
lvEmployee.DataSource = GetEmployee("Select * from Employee");
lvEmployee.DataBind();
lvEmployee.EditIndex = -1;
}
protected void lvEmployee_ItemInserting(object sender, ListViewInsertEventArgs e)
{
string name = "", dept = "", age = "", address = "";
TextBox txt = (e.Item.FindControl("EmpNameTextBox")) as TextBox;
if (txt != null)
name = txt.Text;
txt = (e.Item.FindControl("DepartmentTextBox")) as TextBox;
if (txt != null)
dept = txt.Text;
txt = (e.Item.FindControl("AgeTextBox")) as TextBox;
if (txt != null)
age = txt.Text;
txt = (e.Item.FindControl("AddressTextBox")) as TextBox;
if (txt != null)
address = txt.Text;
string INSERTQuery = "INSERT INTO [Employee] (EmpName,Department,Age,Address) VALUES ('" + name + "','" + dept + "','" + age + "','" + address + "')";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand(INSERTQuery, con);
com.ExecuteNonQuery();
con.Close();
lvEmployee.DataSource = GetEmployee("Select * from Employee");
lvEmployee.DataBind();
lvEmployee.EditIndex = -1;
}
и код моей мастер-страницы для загрузки этой страницы:
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<!-- Initial the Page which is going to show the details of the sub-menu -->
<asp:ContentPlaceHolder id="ContentPlaceHolder3" runat="server" Visible="false">
</asp:ContentPlaceHolder>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="Button3" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="Button4" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="LinkButton2" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="LinkButton3" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="LinkButton4" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="LinkButton5" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="LinkButton6" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="LinkButton7" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="LinkButton8" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="LinkButton9" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
потому что сначала я хочу выполнить частичное обновление, я установил для Visible of ContentPlaceHolder3 значение false, и как только пользователь щелкнет по соответствующей ссылке, я просто установил его как истинное по коду.
не могли бы вы подсказать мне, как загрузить этот вид aspx-страницы на мастер-страницу.
ценим ваше внимание.