这是效果图,实现的具体代码如下:
aspx页面:
<body> <form id="form1" runat="server"> <div> <table> <tr> <td> 问卷调查管理 >> 问卷列表 </td> </tr> <tr> <td> <asp:Panel ID="p_search" runat="server"> 调查问卷: <asp:DropDownList ID="ddl_paper" runat="server" AutoPostBack="true"> </asp:DropDownList> <%--<asp:Button ID="btn_Search" runat="server" Text="查 询" Width="51px" />--%> </asp:Panel> </td> </tr> <tr> <td> <yyc:SmartGridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting="True" Width="100%" DataSourceID="ObjectDataSource1" AllowPaging="True" OnRowDataBound="GridView1_RowDataBound" PageSize="10"> <Columns> <asp:TemplateField> <%--<ItemStyle HorizontalAlign="Center" />--%> <ItemTemplate> <asp:HiddenField ID="hfTmpId" runat="server" Value='<%# Eval("TMP_ID")%>' /> <table> <tr> <td colspan="2"> <asp:Label ID="lbl_Order" runat="server" Text='<%# Eval("VoteOrder") %>'></asp:Label> <asp:Label ID="LVetoco" runat="server" Text='<%# Eval("VOTECO")%>'></asp:Label> </td> </tr> <tr> <td> <asp:GridView ID="GridView2" runat="server" Width="600px" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="CS" HeaderText="选项" HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="70%" ItemStyle-HorizontalAlign="Left" /><%--HeaderStyle-Width="250px"--%> <asp:BoundField DataField="CS_PERCENT" ItemStyle-HorizontalAlign="Center" HeaderText="占百分比" ItemStyle-Width="15%" HeaderStyle-HorizontalAlign="Center" /><%--HeaderStyle-Width="100px"--%> <asp:BoundField DataField="CS_COUNT" ItemStyle-HorizontalAlign="Center" HeaderText="投票人数" ItemStyle-Width="15%" HeaderStyle-HorizontalAlign="Center" /><%--HeaderStyle-Width="100px"--%> </Columns> </asp:GridView> </td> <td valign="bottom"> <asp:Button ID="btn_Detail" runat="server" Text="其他建议详情" Visible="false" OnClientClick='<%# "WordDetail(" + Eval("PersonWord_ID") + ")" %>' /> </td> </tr> </table> </ItemTemplate> </asp:TemplateField> </Columns> <PagerTemplate> <asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First" CommandName="Page">首页</asp:LinkButton> <asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev" CommandName="Page">上一页</asp:LinkButton> <asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next" CommandName="Page">下一页</asp:LinkButton> <asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last" CommandName="Page">尾页</asp:LinkButton> 第<asp:Label ID="lbpage" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>'> </asp:Label>页 共<asp:Label ID="lbpagecount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>'></asp:Label>页 跳到<input id="txtPage" type="text" value='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' style=" 30px; height: 20px" /> <%--<asp:TextBox ID="txtPage" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' Width="30px" Height="20px"></asp:TextBox>--%> <input id="btn_Go" type="button" value="GO" onclick="PageSearch();" class="button" style="height: 25px" /> </PagerTemplate> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Center" /> </yyc:SmartGridView> </td> </tr> </table> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="ZWW.BLL.VoteDateSource" MaximumRowsParameterName="pageSize" StartRowIndexParameterName="startIndex" EnablePaging="True" SelectCountMethod="GetTotal"> <SelectParameters> <asp:ControlParameter ControlID="ddl_paper" Name="vp_id" PropertyName="SelectedValue" Type="Int64" /> </SelectParameters> </asp:ObjectDataSource> </div> </form> <script type="text/javascript"> function WordDetail(tmpID) { //alert(tmpID); var pbURL = 'PersonWord.aspx?TMP_ID=' + tmpID + '&mode=' + new Date().getTime(); ; var word = window.showModalDialog(pbURL, "", "dialogHeight:430px;dialogWidth:700px;center:yes;status:no"); } </script> </body>
cs后台页面:
namespace ZWW.Admin.VoteAdmin { public partial class VoteListShow : System.Web.UI.Page { public long TMP_ID; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PageControlBind(); } } /// <summary> /// 页面控件加载值 /// </summary> protected void PageControlBind() { ddl_paper.DataSource = VoteManage.GetAllPaper(); ddl_paper.DataTextField = "VP_NAME"; ddl_paper.DataValueField = "VP_ID"; ddl_paper.DataBind(); ddl_paper.Items.Insert(0, new ListItem("请选择调查问卷", "0")); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { VoteManage votemanger = new VoteManage(); if (e.Row.RowType == DataControlRowType.DataRow) { GridView gv = (GridView)e.Row.FindControl("GridView2"); string voceto = ((Label)e.Row.FindControl("LVetoco")).Text; Button detail = (Button)e.Row.FindControl("btn_Detail"); long tem_id = Convert.ToInt64(((HiddenField)e.Row.FindControl("hfTmpId")).Value); gv.DataSource = VoteManage.GetChoice(tem_id); gv.DataBind(); if (votemanger.IfIsInput(tem_id,ref TMP_ID)) { detail.Visible = true; if (TMP_ID == tem_id) { detail.Text = "详情"; } } } } } }
BLL方法:
public static IEnumerable GetChoice(long tem_id) { //List<string> xuanxiang = new List<string>(); ////var data = DataClassesDataContext.Default.T_VOTE.Where(v => v.VOTECO == vp_name).ToList(); //DataClassesDataContext.Default.T_VOTE.Where(v => v.VOTECO == vp_name).Select(v => new //{ //}); var res = DataClassesDataContext.Default.P_GET_VOTE_STATISTIC_DATAS(tem_id); if (res != null) { var data = res.Select(v => new { v.CS, CS_PERCENT = Math.Round((double)v.CS_PERCENT,2).ToString() + "%", v.CS_COUNT }); return data; } else { return null; } }