⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookcomment.aspx

📁 asp.net 做的个人图书站点应用
💻 ASPX
字号:
<%@ Page Language="C#" MasterPageFile="~/Default.master" Title="图书评论页" %>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        //Page.MaintainScrollPositionOnPostBack = true;
        if (!IsPostBack)
        {
            int i = Convert.ToInt32(Request.QueryString["Page"]);
            if (i >= 0) FormView1.PageIndex = i;
        }


      //  ShowControl();


    }

    private void ShowControl()
    {
        if (Membership.GetUser() != null)
        {
            FormView1.FindControl("AddComment").Visible = true;
            DataList datalist = (DataList)FormView1.FindControl("DataList1");
            bool has = Roles.IsUserInRole(Membership.GetUser().UserName, "Administrators");
            if (has)
            {
                foreach (DataListItem item in datalist.Items)
                    item.FindControl("CommentDelete").Visible = true;
            }
            else
            {
                foreach (DataListItem item in datalist.Items)
                    item.FindControl("CommentDelete").Visible = false;
            }
        }
        else
        {
            DataList datalist = (DataList)FormView1.FindControl("DataList1");
            FormView1.FindControl("AddComment").Visible = false;
            foreach (DataListItem item in datalist.Items)
                item.FindControl("CommentDelete").Visible = false;
        }
    }
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);
        ShowControl();
    }

       

    protected void CommentDelete_Click(object sender, ImageClickEventArgs e)
    { 
      // DataList datalist =(DataList)FormView1.FindControl("DataList1");
       // HiddenField1.Value = datalist.SelectedValue.ToString();
      //  HiddenField1.Value = "12";
        //ObjectDataSource2.DeleteParameters.Add(new Parameter("CommentID", TypeCode.Int32, datalist.SelectedValue.ToString ()));
      //  ObjectDataSource2.DeleteParameters.Add(CommentID, (int)datalist.SelectedIndex);
       
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
	<div class="shim solid"></div>
		<div class="page" id="details">
		<asp:formview id="FormView1" runat="server"	datasourceid="ObjectDataSource1" cssclass="view" DataKeyNames ="BookID"
			borderstyle="none" borderwidth="0" CellPadding="0" cellspacing="0" EnableViewState="false" AllowPaging="true" >
			<itemtemplate>
			
				<div class="buttonbar buttonbar-top">
					<a href="BookCategory.aspx"><asp:image ID="Image1" runat="Server"	 skinid="gallery" /></a>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<asp:ImageButton ID="ImageButton9" Runat="server" CommandName="Page" CommandArgument="First" skinid="first"/>
					<asp:ImageButton ID="ImageButton10"	Runat="server" CommandName="Page" CommandArgument="Prev" skinid="prev"/>
					<asp:ImageButton ID="ImageButton11"	Runat="server" CommandName="Page" CommandArgument="Next" skinid="next"/>
					<asp:ImageButton ID="ImageButton12"	Runat="server" CommandName="Page" CommandArgument="Last" skinid="last"/>
				</div>
				<p>图书名:<%# Server.HtmlEncode(Eval("BookName").ToString()) %></p>
				<table border="0" cellpadding="0" cellspacing="0" class="photo-frame">
					<tr>
						<td class="topx--" style="width: 4px; height: 18px"></td>
						<td class="top-x-" style="width: 200px; height: 18px"></td>
						<td class="top--x" style="width: 4px; height: 18px"></td>
						<td style="height: 18px"><p>ISBN:<%# Server.HtmlEncode(Eval("ISDN").ToString())%></p></td>
					</tr>
					<tr>
						<td class="midx--" style="width: 4px; height: 38px;"></td>
						<td style="width: 200px; height: 38px;"><img src="Handler.ashx?BookID=<%# Eval("BookID") %>&Size=L" class="photo_198" style="border:4px solid white" alt='照片编号 <%# Eval("BookID") %>' /></td>
						<td class="mid--x" style="width: 4px; height: 38px;"></td>
						<td style="height: 38px"><p>添加者:<%#Server.HtmlEncode(Eval("UserID").ToString ()) %></p></td>
					</tr>
					<tr>
						<td class="botx--" style="width: 4px; height: 18px;"></td>
						<td class="bot-x-" style="width: 200px; height: 18px;"></td>
						<td class="bot--x" style="width: 4px; height: 18px;"></td>
				   <td style="height: 18px"><p>添加时间:<%# Server.HtmlEncode(Eval("AddDateTime").ToString())%></p></td>

					</tr>
				</table>
				<p>图书简述: <%# Server.HtmlEncode(Eval("BookTips").ToString()) %>&nbsp;</p>
				 <div class="buttonbar">
					<a href="BookCategory.aspx"><asp:image ID="Image2" runat="Server"	 skinid="gallery" /></a>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<asp:ImageButton ID="ImageButton1" Runat="server" CommandName="Page" CommandArgument="First" skinid="first"/>
					<asp:ImageButton ID="ImageButton2" Runat="server" CommandName="Page" CommandArgument="Prev" skinid="prev"/>
					<asp:ImageButton ID="ImageButton3" Runat="server" CommandName="Page" CommandArgument="Next" skinid="next"/>
					<asp:ImageButton ID="ImageButton4" Runat="server" CommandName="Page" CommandArgument="Last" skinid="last"/>
				</div>
                <asp:DataList ID="DataList1" runat="server" DataSourceID="ObjectDataSource2"  >
                    <ItemTemplate>
                        <table>
                            <tr>
                                <td align="left" style="width: 126px; height: 18px">
                                    评论标题:</td>
                                <td align="left" style="width: 186px; height: 18px">
                                    <asp:Label ID="Caption" runat="server"  Width="133px"  Text='<%#Eval("Caption") %>'></asp:Label></td>
                                <td align="left" style="width: 136px; height: 18px">
                                </td>
                                <td align="left" style="width: 238px; height: 18px">
                                </td>
                            </tr>
                            <tr>
                                <td align="left" colspan="4" rowspan="2" valign="middle" style="height: 59px">
                                    <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="686px" Text ='<%#Eval("CommentContext") %>' ReadOnly ="true" BackColor="#E0E0E0" BorderStyle="None" Height="51px"></asp:TextBox></td>
                            </tr>
                            <tr>
                            </tr>
                            <tr>
                                <td align="left" style="width: 126px; height: 17px">
                                    评论人:</td>
                                <td align="left" style="width: 186px; height: 17px">
                                    <asp:Label ID="UserID" runat="server" Width="133px" Text='<%#Eval("UserID") %>'></asp:Label></td>
                                <td align="left" style="width: 136px; height: 17px">
                                    评论时间:</td>
                                <td align="left" style="width: 238px; height: 17px">
                                    <asp:Label ID="AddTime" runat="server"  Width="165px" Text ='<%#Eval("CommentTime") %>'></asp:Label>
                                    <asp:ImageButton ID="CommentDelete" runat="server" SkinID="delete" Visible="false" OnClick="CommentDelete_Click" CommandName="Delete"  /></td>
                            </tr>
                        </table>
                        &nbsp;&nbsp;<br />
                        &nbsp;<br />
                    </ItemTemplate>
                    <SeparatorTemplate>
                        <span  >---------------------------------------------------------------------------------------------------</span>
                    </SeparatorTemplate>
                    <FooterTemplate>
                        <span style="font-size: 32pt; color: green">------------------------------</span>
                    </FooterTemplate>
                </asp:DataList>
                <asp:formview  ID="AddComment" runat ="server" DataSourceID="ObjectDataSource2" Visible ="true" DefaultMode="Insert"  >
                <InsertItemTemplate>
                <div style="width: 708px; height: 100px">
                    <table style="width: 686; height: 100px">
                        <tr>
                            <td style="width: 70px; height: 36px" align="left" valign="middle">
                             评论标题:
                            </td>
                            <td style="width: 616px; height: 36px" align="left" valign="middle">
                            <asp:TextBox ID="AddCaption" runat ="server" Width="323px" Text ='<%#Bind("Caption") %>'></asp:TextBox>
                                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                                <asp:ImageButton ID="InsertComment" runat="server" SkinID="Add" CommandName="Insert" /></td>
                        </tr>
                        <tr>
                            <td style="height: 90px" align="left" colspan="2" valign="top">
                                <asp:TextBox ID="TextBox2" runat="server" Height="68px" TextMode="MultiLine" Width="686px" Text='<%#Bind("CommentContext") %>'></asp:TextBox></td>
                        </tr>
                    </table>
                </div>
                </InsertItemTemplate>
      </asp:formview>
			</itemtemplate>
		</asp:formview>
	</div>
	<asp:ObjectDataSource ID="ObjectDataSource1" Runat="server" TypeName="BookManager" 
		SelectMethod="GetBookbyCategory">
		<SelectParameters>
			<asp:QueryStringParameter Name="CategoryID" Type="Int32" QueryStringField="CategoryID" DefaultValue="0"/>
		</SelectParameters>
	</asp:ObjectDataSource>
    <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" TypeName="CommentManager"
     SelectMethod="GetCommentByBookID" InsertMethod ="AddComment" DeleteMethod ="DeleteComment">
     <SelectParameters>
     <asp:ControlParameter Name ="BookID" Type ="Int32" ControlID="FormView1" PropertyName="SelectedValue" />
     </SelectParameters>
     <InsertParameters>
      <asp:ControlParameter Name ="BookID" Type ="Int32" ControlID="FormView1" PropertyName="SelectedValue" />
     </InsertParameters>
     <DeleteParameters>
     <asp:Parameter Name="CommentID" Type="Int32" DefaultValue="12" />
     </DeleteParameters>
    </asp:ObjectDataSource>
    <asp:HiddenField ID="HiddenField1" runat="server" Visible="False" />
    <br />
</asp:Content>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -