2012-07-14 48 views
0

我正在使用Telerik列表視圖。我剛剛添加了一個SqlDataSource,我想在服務器端提供select命令。但是當我想在.cs文件中訪問它時,即使沒有顯示任何控件,SqlDataSource1也無法訪問。我添加了一個標籤,當我嘗試Label1.Text比label1無法在.cs文件中訪問。Asp控件不能正常工作

<%@ Page Title="" Language="C#" MasterPageFile="~/PortalSite.Master" AutoEventWireup="true" CodeBehind="category.aspx.cs" Inherits="NoidaPortal.category" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 

<style type="text/css"> 
    .rdpWrap .RadInput, .rdpWrap .rdpPagerButton, .rdpWrap .rdpPagerLabel 
    { 
     float: left; 
    } 
</style> 
</head> 
<body> 
<form id="form1" runat="server"> 
<asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource> 

<div> 
    <!-- content start --> 
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> 

     <script type="text/javascript"> 
      function RequestStart(sender, eventArgs) { 
       //disable ajax on update/insert operation to upload the image 
       if ((eventArgs.get_eventTarget().indexOf("Update") > -1) || (eventArgs.get_eventTarget().indexOf("PerformInsert") > -1)) { 
        eventArgs.set_enableAjax(false); 
       } 
      } 
     </script> 

    </telerik:RadCodeBlock> 
    <table> 
     <tr> 
      <td> 
       <asp:Panel ID="ListViewPanel1" runat="server"> 
        <telerik:RadListView ID="RadListView1" DataSourceID="SqlDataSource1" runat="server" 
         ItemPlaceholderID="CustomersContainer" DataKeyNames="ArchitectId" AllowPaging="True" 
         > 
         <LayoutTemplate> 
          <!-- Set the id of the wrapping container to match the CLIENT ID of the RadListView control to display the ajax loading panel 
        In case the listview is embedded in another server control, you will need to append the id of that server control --> 
          <fieldset id="FiledSet1" style="width:435px;"> 
           <legend>Customers</legend> 
           <table cellpadding="0" cellspacing="0" width="100%"> 
            <tr> 
             <td> 
              <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1" 
               PageSize="5" Width="435px"> 
               <Fields> 
                <telerik:RadDataPagerButtonField FieldType="FirstPrev" /> 
                <telerik:RadDataPagerButtonField FieldType="Numeric" PageButtonCount="6" /> 
                <telerik:RadDataPagerButtonField FieldType="NextLast" /> 
                <telerik:RadDataPagerPageSizeField PageSizeText="Page size: " /> 



               </Fields> 
              </telerik:RadDataPager> 
             </td> 
            </tr> 
           </table> 
           <asp:PlaceHolder ID="CustomersContainer" runat="server" /> 
           <div style="clear: both" /> 
           <br /> 
           <br /> 
           <table style="width: 100%;"> 
            <tr> 
             <%--<td style="width: 25%;"> 
              <asp:Button ID="btnInitInsert" runat="server" Text="Insert Customer" OnClick="btnInitInsert_Click" /> 
             </td>--%> 
             <td style="text-align:center; width: 75%;"> 
              <asp:Label ID="lblSort1" runat="server" Text="Sort by:" Style="padding-right: 5px;" /> 
              <telerik:RadComboBox ID="ddListSort" runat="server" AutoPostBack="true"> 
               <Items> 
                <telerik:RadComboBoxItem Text="-Select field to sort-" Value="" /> 
                <telerik:RadComboBoxItem Text="Company name" Value="ArchitectName" /> 
                <telerik:RadComboBoxItem Text="Sector" Value="Sector" /> 

               </Items> 
              </telerik:RadComboBox> 
             </td> 
            </tr> 
           </table> 
           </div> 
          </fieldset> 
         </LayoutTemplate> 
         <ItemTemplate> 
          <!--The widths/heights of the fieldset/outer tables in the item/edit/insert templates should match to avoid wrapping or visual discrepancies 
         in the tiles layout--> 
          <fieldset style="float: left; width: 410px; height: 215px; margin-top:10PX;"> 
           <legend style="font-weight:bold"> 
            <%# Eval("ArchitectName")%></legend> 
           <table cellpadding="0" cellspacing="0" style="height: 100%;" width="370px"> 
            <tr> 
             <td> 
              <table cellpadding="0" cellspacing="0"> 
               <tr> 
                <td> 
                 <table cellpadding="0" cellspacing="0"> 
                  <tr> 
                   <td style="font-weight:bold; width:25%"> 
                    Address: 
                   </td> 
                   <td style="width:auto; width:75%;"> 
                    <%#Eval("ArchitectAddress")%> 
                   </td> 
                  </tr> 
                  <tr> 
                   <td style="width:25%; font-weight:"> 
                    City: 
                   </td> 
                   <td> 
                    <%# Eval("Contact1")%> 
                   </td> 
                  </tr> 
                  <tr> 
                   <td style="font-weight:bold"> 
                    Country: 
                   </td> 
                   <td> 
                    <%# Eval("Contact2")%> 
                   </td> 
                  </tr> 
                  <tr> 
                   <td style="font-weight:bold"> 
                    Phone: 
                   </td> 
                   <td> 
                    <%#Eval("Email_Id")%> 
                   </td> 
                  </tr> 
                  <tr> 
                   <td style="font-weight:bold"> 
                    Website: 
                   </td> 
                   <td> 
                    <%#Eval("Website")%> 
                   </td> 
                  </tr> 
                 </table> 
                </td> 
               </tr> 
              </table> 
             </td> 
            </tr> 
           </table> 
          </fieldset> 
          </ItemTemplate> 
         <EmptyDataTemplate> 
          <fieldset style="width: 800px"> 
           <legend>Customers</legend>No records for customers available. 
          </fieldset> 
         </EmptyDataTemplate> 
        </telerik:RadListView> 
       </asp:Panel> 
      </td> 
     </tr> 


    </table> 
    <br /> 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:dbPortalConnectionString %>" 
     SelectCommand="SELECT * FROM [Architect]" > 
    </asp:SqlDataSource> 

/div> 
</form> 
</body> 
</html> 
</asp:Content> 

,這是我的aspx.cs類

using System; 
using System.Collections.Generic; 
using System.Collections; 
using System.Configuration; 
using System.Web.Security; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Data; 
using System.Xml.Linq; 
using System.Data.SqlClient; 
namespace NoidaPortal 
{ 

     public partial class category : System.Web.UI.Page 
     { 
      protected void Page_Load(object sender, EventArgs e) 
      { 
       if (IsPostBack == false) 
        { 
         string s = Request.QueryString["cat"]; 
         string s1 = Request.QueryString["sub"]; 

         **I Just want to give here a SqlDataSource.Select command** 
        } 
      } 
    } 
+0

聽起來像你的代碼隱藏文件搞砸了。將您的ASPX頁面與您的代碼隱藏文件一起發佈。 – 2012-07-14 16:15:05

+0

okk我把我的代碼。 – 2012-07-14 16:25:57

+0

plz檢查它。我只是把我的代碼和代碼behi] – 2012-07-14 17:01:15

回答

0

,因爲你沒有提到這是你的頁面代碼隱藏可能的。作爲第一行添加到您的aspx頁面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="yourfile.aspx.cs" Inherits="YourProjectName.YourASPXPageName" %> 
+0

我做到了,而且它不工作。 – 2012-07-14 16:19:54

+0

只是不要複製它,代替你的價值。 – 2012-07-14 16:20:19

+0

Plz檢查我的代碼和類背後的代碼 – 2012-07-14 17:01:36

0

,因爲您使用的是主你有一些東西不是你的內容佔位符允許的。你沒有對你的控件進行智能感知的原因是因爲該頁面不會進行補充。

刪除這些標籤:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<body> 
<form id="form1" runat="server"> 

然後嘗試編譯您的應用程序。修復編譯器拋出的任何錯誤並重新編譯。一旦應用程序可編譯,您的智能感知應該重新開始工作。

+0

Chris Gessler,謝謝你關於我現在刪除這些標籤,甚至比它不工作..它編譯得很好,但是當我想在.cs文件intellicence SqlDataSource沒有顯示它。 – 2012-07-14 17:28:51

+0

,然後輸入SqlDataSource2。 ? – 2012-07-14 17:50:08

+0

是的,當我輸入sqlDataSource1或sqlDataSource2即使我使用標籤並嘗試訪問label1,也沒有顯示任何內容。比它也不工作.. – 2012-07-14 18:03:21

0

是的,我在這裏找到了解決方案...我必須通過右鍵單擊ProjectFolder將其轉換爲webApplication,然後單擊「轉換爲Web應用程序」。比它的智能感覺開始工作。