2013-12-21 36 views
0

我在我的頁面中有一個搜索按鈕。當我點擊該按鈕時,分頁的數據列表將顯示結果爲 。我想使用modalPopupExtender與Datalist和集合分頁器。可能嗎 ?這裏是我試過的代碼,但它不工作:使用ModalPopupExtender與datalist和集合頁面

<asp:Label ID="Label5" runat="server"></asp:Label> 
<asp:ModalPopupExtender ID="Label1_ModalPopupExtender" runat="server" CancelControlID="btThoat" 
    DynamicServicePath="" Enabled="True" PopupControlID="Panel1" TargetControlID="Label5"> 
</asp:ModalPopupExtender> 
<asp:Panel ID="Panel1" runat="server"> 
    <div style="margin-left: 20px; padding-top: 50px"> 
     <asp:Label ID="lbl_CS" runat="server" Text="Ca sĩ" ForeColor="#FF33CC" Font-Size="18" 
      Visible="True"></asp:Label> 
     <asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#CC9966" 
      BorderStyle="None" BorderWidth="1px" CellPadding="4" GridLines="Both" RepeatColumns="4" 
      OnItemDataBound="DataList1_ItemDataBound"> 
      <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> 
      <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" /> 
      <ItemStyle BackColor="White" ForeColor="#330099" /> 
      <ItemTemplate> 
       <table> 
        <tr> 
         <td style="width: 10px"> 
          <asp:RadioButton ID="rd_CS" runat="server" GroupName="Casi" Text='<%# Eval("MaCS")%>' 
           AutoPostBack="False"></asp:RadioButton> 
         </td> 
         <td style="width: 75px"> 
          <asp:Image ID="Img_Casi" runat="server" ImageUrl='<%#Eval("Hinhanh")%>' Width="75px" 
           Height="75px" BorderColor="#66FF33" /> 
         </td> 
         <td style="width: 50px"> 
          <asp:Label ID="lbl_Ten" runat="server" Text='<%#Eval("TenCS")%>'></asp:Label> 
         </td> 
         <td style="width: 40px"> 
          <asp:Label ID="lbl_Ngaysinh" runat="server" Text='<%#Eval("Ngaysinh")%>'></asp:Label> 
         </td> 
        </tr> 
       </table> 
      </ItemTemplate> 
      <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" /> 
     </asp:DataList> 
     <cc2:CollectionPager ID="CollectionPager1" runat="server" MaxPages="1000" PagingMode="QueryString" 
      BackNextDisplay="Buttons" QueryStringKey="Datalist1"> 
     </cc2:CollectionPager> 
    </div> 
</asp:Panel> 

代碼在C#:

bool Checkcs() 
    { 
     string cs = "select MaCS, Quocgia, TenCS, Hinhanh, Thongtin, cast(convert(char(11), Ngaysinh, 113) as char) as Ngaysinh from casi where tencs like N'%" + txt_CS.Text + "%'"; 
     da = new SqlDataAdapter(cs, cnn); 
     dtSP = new DataTable(); 
     cnn.Open(); 
     da.Fill(dtSP); 
     cnn.Close(); 
     CollectionPager1.PageSize = 8; 
     CollectionPager1.DataSource = dtSP.DefaultView; 
     CollectionPager1.BindToControl = DataList1; 
     DataList1.DataSource = CollectionPager1.DataSourcePaged; 
     DataList1.DataBind(); 
     Label1_ModalPopupExtender.Show(); 
     if (dtSP.Rows.Count != 0) 
      return true; 
     else 
      return false; 
    } 

protected void img_CheckCS_Click(object sender, ImageClickEventArgs e) 
    { 
     Checkcs(); 
    } 

如果這是不可能的。還有另一種方法可以做到嗎?如果它是可能的。你能告訴我一個示例代碼嗎?任何幫助都會很棒。

+0

沒有可能在這裏編程。也許我們有解決方法和出路。即使大部分東西已經在其他地方完成了,你只需要打它。 – 2013-12-21 07:29:42

+0

是的,它可能。你在這個 –

+0

@VigneshKumar遇到了什麼問題我試了上面的代碼,但沒有顯示出來。如果你給我看一個示例代碼,那將是非常棒的。 –

回答

0

這是樣本。請參考此

.modalBackground { background-color:Gray; filter:alpha(opacity = 80); 不透明度:0.8; z-index:10000; }

.modalPopupCss { 
    background-color: white; 
    border-width: 1px; 
    border-style: solid; 
    border-color: #0066B3; 
    padding: 3px; 
} 

ASPX

<div> 
      <asp:ModalPopupExtender BackgroundCssClass="modalBackground" ID="Label1_ModalPopupExtender" CancelControlID="Button2" runat="server" Enabled="True" PopupControlID="Panel1" TargetControlID="lbl_CS"></asp:ModalPopupExtender> 
      <asp:Panel ID="Panel1" CssClass="modalPopupCss" runat="server"> 
       <div style="margin-left: 20px; padding-top: 50px"> 
        <asp:Label ID="lbl_CS" runat="server" Text="" ForeColor="#FF33CC" Font-Size="18" Visible="True"></asp:Label> 
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> 
        </asp:ToolkitScriptManager> 
        <asp:GridView ID="GridView1" runat="server"></asp:GridView> 
        <asp:Button ID="Button2" runat="server" Text="Close" /> 
       </div> 
      </asp:Panel> 

      <asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" /> 

Aspx.Cs

DataTable dt = new DataTable(); 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     dt.Columns.Add("ID"); 
     dt.Columns.Add("Name"); 
     dt.Columns.Add("State"); 
    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
     dt.Rows.Add("1", "Vignesh", "True"); 
     GridView1.DataSource = dt; 
     GridView1.DataBind(); 
     Label1_ModalPopupExtender.Show(); 

    } 
+0

它的工作,但是當我點擊收集傳呼機的下一頁。 modalpopupextender消失。您可以在示例代碼中追加集合傳呼機嗎? –

+0

當頁面重新加載時,模態彈出窗口會消失。所以你需要使用modelpopup.Show()方法 –

+0

我可以重新加載只有面板? –