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();
}