M
Mike P
I have created my own generic class that I need to persist across
postbacks. Here is my code :
private void AgentSelector()
{
List<Agent> agentList = new List<Agent>();
CheckBox chk;
int a = 0;
foreach (GridViewRow rowItem in GridView1.Rows)
{
chk =
(CheckBox)(rowItem.Cells[0].FindControl("AgentSelector"));
if (chk.Checked)
{
Agent agent = new Agent();
agent.AgentID =
Convert.ToInt32(rowItem.Cells[1].Text);
agent.AgentName =
Convert.ToString(rowItem.Cells[2].Text);
agentList.Add(agent);
a++;
}
}
GridView2.DataSource = agentList;
GridView2.DataBind();
Session["AgentList"] = agentList;
pnlConfirm.Visible = false;
pnlAgentSelected.Visible = true;
}
And then I am taking the list out of session in another method :
protected void btnInsertAgent_Click(object sender, EventArgs e)
{
List<Agent> agentList = (List<Agent>)Session["AgentList"];
}
Is this the right way to use generics? I am just wondering as I have
never seen anyone else use generics like this.
postbacks. Here is my code :
private void AgentSelector()
{
List<Agent> agentList = new List<Agent>();
CheckBox chk;
int a = 0;
foreach (GridViewRow rowItem in GridView1.Rows)
{
chk =
(CheckBox)(rowItem.Cells[0].FindControl("AgentSelector"));
if (chk.Checked)
{
Agent agent = new Agent();
agent.AgentID =
Convert.ToInt32(rowItem.Cells[1].Text);
agent.AgentName =
Convert.ToString(rowItem.Cells[2].Text);
agentList.Add(agent);
a++;
}
}
GridView2.DataSource = agentList;
GridView2.DataBind();
Session["AgentList"] = agentList;
pnlConfirm.Visible = false;
pnlAgentSelected.Visible = true;
}
And then I am taking the list out of session in another method :
protected void btnInsertAgent_Click(object sender, EventArgs e)
{
List<Agent> agentList = (List<Agent>)Session["AgentList"];
}
Is this the right way to use generics? I am just wondering as I have
never seen anyone else use generics like this.