0

I'm trying to convert my Gridview from using an SQL datasource to using an object that I am storing as an Application State variable.

I have the object stored, and then called into the page I want to load it from

if (Application["AllLeads"] != null)
{
    Leads allLeads = Application["AllLeads"] as Leads;
}

My current grid is declared as

<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">

Datasource:

<asp:SqlDataSource
            ID="Searchdatasource"
            runat="server"
            DataSourceMode="DataSet"></asp:SqlDataSource>

The leads object contains:

public Dictionary<int, LeadModel> LeadList = new Dictionary<int, LeadModel>();

The lead model:

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

I am using the current datasource to get the fields returned from my SQL query.

Searchdatasource.SelectCommand = "SELECT DISTINCT [tbl_UserEvents].*  FROM [tbl_UserEvents] ...;

I've looked into ObjectDataSource briefly, but I only found more MySQL references, or method calls. I don't want to call any methods, rather, use the variable that is accessible in the Lead object to auto populate the grid.

Any ideas?

Edit:

I figured it out. :)

Code:

<asp:ObjectDataSource ID="LeadDataSource" runat="server" TypeName="[Proj].Data_Classes.Leads" DataObjectTypeName="[Proj].Data_Classes.LeadModel" SelectMethod="MatchLead">
</asp:ObjectDataSource>

My only question now is how do I use the Object stored in the Application State?

I believe this may be working:

if (Application["AllLeads"] != null)
{
    Leads allLeads = Application["AllLeads"] as Leads;
    ObjectDataSource1.TypeName = allLeads.ToString();
}
Soulevoker
  • 163
  • 8

0 Answers0