我正在尝试将我的 Gridview 从使用 SQL 数据源转换为使用我存储为应用程序状态变量的对象。
我存储了对象,然后调用到我想从中加载它的页面
if (Application["AllLeads"] != null)
{
Leads allLeads = Application["AllLeads"] as Leads;
}
我当前的网格被声明为
<asp:GridView runat="server" class="table" HeaderStyle-ForeColor="White" EmptyDataText="No Leads Found" ShowHeader="true" DataSourceID="Searchdatasource" AllowPaging="True" PageSize="200" AutoGenerateColumns="false" DataKeyNames="ID" ID="gview">
数据源:
<asp:SqlDataSource
ID="Searchdatasource"
runat="server"
DataSourceMode="DataSet"></asp:SqlDataSource>
线索对象包含:
public Dictionary<int, LeadModel> LeadList = new Dictionary<int, LeadModel>();
主要型号:
public string LeadName { get; set; }
public string City { get; set; }
public string State { get; set; }
public String LeadZip { get; set; }
public string EventDate { get; set; }
public string Services { get; set; }
public int LeadCost { get; set; }
public int LeadID { get; set; }
public Dictionary<int, string> LOSResponses { get; set; }
public Dictionary<int, bool> QuestionRequired { get; set; }
我正在使用当前数据源来获取从我的 SQL 查询返回的字段。
Searchdatasource.SelectCommand = "SELECT DISTINCT [tbl_UserEvents].* FROM [tbl_UserEvents] ...;
我简要地研究了 ObjectDataSource,但我只发现了更多的 MySQL 引用或方法调用。我不想调用任何方法,而是使用 Lead 对象中可访问的变量来自动填充网格。
有任何想法吗?
编辑:
我想到了。:)
代码:
<asp:ObjectDataSource ID="LeadDataSource" runat="server" TypeName="[Proj].Data_Classes.Leads" DataObjectTypeName="[Proj].Data_Classes.LeadModel" SelectMethod="MatchLead">
</asp:ObjectDataSource>
我现在唯一的问题是如何使用存储在应用程序状态中的对象?
我相信这可能有效:
if (Application["AllLeads"] != null)
{
Leads allLeads = Application["AllLeads"] as Leads;
ObjectDataSource1.TypeName = allLeads.ToString();
}