2013-03-22 186 views
0

我有一个网格视图,存储过程设置在SQL.I有三个控件2 dropdown list'stexbox与jQuery日期选择器。我的问题是gridview没有显示在页面加载。但是,当我开始添加控件时,gridview突然显示。从调试,我推测,与jQuery的日期选择器的文本框没有通过NULL值到指定的存储过程,但我还是想知道,如果它是cause.This是代码..在页面上显示网格视图加载

.aspx的代码

<div class="datarange"> 
     <asp:DropDownList ID="categoryDDL" AutoPostBack="true" AppendDataBoundItems="true" runat="server"> 
      <asp:ListItem Text="Select Category" Value=" " /> 
     </asp:DropDownList> 
     <asp:DropDownList ID="brokerDDL" AutoPostBack="true" runat="server"></asp:DropDownList> 
     <asp:TextBox ID="openDate" AutoPostBack="true" runat="server"></asp:TextBox> 

    </div> 
    <br /> 
    <%-- SQL DATA SOURCE PARAMETERS --%> 
    <asp:SqlDataSource ID="SqlRAListings" runat="server" ConnectionString="<%$ ConnectionStrings:kmc_SalesPipelineConnectionString %>" SelectCommand="RecentlyAddedListings" SelectCommandType="StoredProcedure"> 
     <SelectParameters> 
      <asp:ControlParameter ControlID="categoryDDL" Name="Category" PropertyName="SelectedValue" Type="String" DefaultValue=" " /> 
      <asp:ControlParameter ControlID="brokerDDL" Name="Broker" PropertyName="SelectedValue" Type="String" DefaultValue=" Select Employee" /> 
      <asp:ControlParameter ControlID="openDate" Name="OpenDate" PropertyName="Text" Type="DateTime" DefaultValue="" /> 
     </SelectParameters> 
    </asp:SqlDataSource> 
    <%-- END OF SQL DATA SOURCE PARAMETERS --%> 


    <%-- GRIDVIEW FOR DISPLAYING RECENTLY ADDED LISTINGS --%> 
    <asp:GridView ID="ralGridView" runat="server" AllowSorting="True" AutoGenerateColumns="False" OnSelectedIndexChanged="ralGridView_SelectedIndexChanged"> 
     <Columns> 
      <asp:TemplateField HeaderText="Opportunity"> 
       <ItemTemplate> 
        <a href="/management/opportunity.aspx?id=<%# Eval("ID") %>" target="_blank"> 
         <%# Eval("Opportunity").ToString() != "" ? Eval("Opportunity") : "Opportunity" %> 
        </a> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:BoundField DataField="ID" HeaderText="ID" 
       SortExpression="ID" InsertVisible="False" ReadOnly="True" /> 
      <asp:BoundField DataField="Category" HeaderText="Category" 
       SortExpression="Category" /> 
      <asp:BoundField DataField="Contact Name" HeaderText="Contact Name" 
       SortExpression="Contact Name" /> 
      <asp:BoundField DataField="Employee" HeaderText="Employee" SortExpression="Employee" /> 
      <asp:BoundField DataField="Open Date" HeaderText="Open Date" SortExpression="Open Date" /> 
      <asp:TemplateField HeaderText="Opportunity from"> 
       <ItemTemplate> 
        <%# Eval("LeadID").ToString().Length > 0 == true ? "Lead System" : "Personal Lead" %> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
    </asp:GridView> 

    <asp:SqlDataSource ID="SqlDbRAListings" runat="server" ConnectionString="<%$ ConnectionStrings:kmc_SalesPipelineConnectionString %>" SelectCommand="RecentlyAddedListings" SelectCommandType="StoredProcedure"> 
     <SelectParameters> 
      <asp:ControlParameter ControlID="categoryDDL" Name="Category" PropertyName="SelectedValue" Type="String" /> 
      <asp:ControlParameter ControlID="brokerDDL" Name="Broker" PropertyName="SelectedValue" Type="String" /> 
      <asp:ControlParameter ControlID="openDate" Name="OpenDate" PropertyName="Text" Type="DateTime" /> 
     </SelectParameters> 
    </asp:SqlDataSource> 
    <%-- END OF GRID VIEW --%> 
</form> 

<script type="text/javascript"> 
    $(function() { 
     var dates = $("#openDate").datepicker({ 
      defaultDate: "+1w", 
      changeMonth: false, 
      numberOfMonths: 1 
     }); 
    }); 

</script> 

C#代码

namespace KMCWebLMS 
{ 
    public partial class RecentlyAssignedLead : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!Page.IsPostBack) 
      { 
       fillCategoryDropDown(); 
       fillBrokerDropDown(); 
      } 
      else 
      { 
       ralGridView.DataSource = SqlDbRAListings; 
       ralGridView.DataBind(); 
      } 
     } 

     public void fillCategoryDropDown() 
     { 
      DataTable categories = new DataTable(); 
      string command = @"SELECT LeadCategory FROM LeadCategory ORDER BY LeadCategory"; 
      ConnectSQL cmd = new ConnectSQL(); 
      SqlDataAdapter adapter = new SqlDataAdapter(cmd.configureSQL(command)); 
      adapter.Fill(categories); 

      try 
      { 
       categoryDDL.DataSource = categories; 
       categoryDDL.DataTextField = "LeadCategory"; 
       categoryDDL.DataValueField = "LeadCategory"; 
       categoryDDL.DataBind(); 
      } 
      catch 
      { 

      } 
     } 

     public void fillBrokerDropDown() 
     { 
      DataTable employees = new DataTable(); 
      string command = @"SELECT TOP 100 [Emp_Name] FROM [kmc_SalesPipeline].[dbo].[vwEmployees] ORDER BY Emp_Name"; 
      ConnectSQL cmd = new ConnectSQL(); 
      SqlDataAdapter adapter = new SqlDataAdapter(cmd.configureSQL(command)); 
      adapter.Fill(employees); 
      try 
      { 
       brokerDDL.DataSource = employees; 
       brokerDDL.DataTextField = "Emp_Name"; 
       brokerDDL.DataValueField = "Emp_Name"; 
       brokerDDL.DataBind(); 
      } 
      catch 
      { 

      } 
     } 

     protected void ralGridView_SelectedIndexChanged(object sender, EventArgs e) 
     { 

     } 
    } 

回答

0

我已经找到了解决问题的办法。为此,我在代码隐藏中声明了存储过程所需的参数,并将其设置为相应的参数。

//STORED PROCEDURE PARAMETERS 
cmd.Parameters.AddWithValue("@OpenDate", OpenDate); 
cmd.Parameters.AddWithValue("@Broker", broker); 
cmd.Parameters.AddWithValue("@Category", category); 

程序会在page_load上显示默认值,显示gridview中的所有数据。在回发时,指定的参数将被设置为当前存储在特定控制参数中的值。

broker = brokerDDL.SelectedValue; 
category = categoryDDL.SelectedValue; 
ralGridView.DataSource = CreateRecentlyAddedTable(); 
ralGridView.DataBind(); 
0

但是从后面的代码,您似乎只在回传填充GridView控件。
对于PageLoad,您只是填充下拉菜单。

不应该在该代码来

ralGridView.DataSource = SqlDbRAListings; 
       ralGridView.DataBind(); 

if (!Page.IsPostBack) 
+0

对不起,它没有工作 – 2013-03-23 11:28:51