Click here to Skip to main content
15,898,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
//this is my code where i have done some calculations and i want it to be run at the time of page //load. how can i do that...
C#
protected void gvUserInfo_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    DataTable dt = new DataTable();
    dt.Columns.Add("sponcorid", typeof(string));
    dt.Columns.Add("leftcount", typeof(int));
    dt.Columns.Add("rightcount", typeof(int));
    dt.Columns.Add("totcount", typeof(int));
    dt.Columns.Add("pair", typeof(int));
    dt.Columns.Add("tot_comission", typeof(float));
    dt.Columns.Add("paid_comission", typeof(float));
    dt.Columns.Add("unpaid_comission", typeof(float));
    //DataRow dr = dt.NewRow();

    Label sponcorid = (Label)e.Item.FindControl("lblsponcorid");
    Label leftcount = (Label)e.Item.FindControl("lblleft");
    Label rightcount = (Label)e.Item.FindControl("lblright");
    Label totcount = (Label)e.Item.FindControl("lbltotcount");
    Label pair = (Label)e.Item.FindControl("lblpair");
    Label tot_comission = (Label)e.Item.FindControl("lbltot_comission");
    Label paid_comission = (Label)e.Item.FindControl("lblpaid_comission");
    Label unpaid_comission = (Label)e.Item.FindControl("lblunpaid_comission");
    double total = Convert.ToInt32(pair.Text.ToString()) * 500;
    tot_comission.Text =total.ToString();

    Label9.Text = sponcorid.Text.ToString();
    Label8.Text = leftcount.Text.ToString();
    Label10.Text = rightcount.Text.ToString();
    Label11.Text = totcount.Text.ToString();
    Label12.Text = pair.Text.ToString();
    Label13.Text = tot_comission.Text.ToString();
    Label15.Text = paid_comission.Text.ToString();
    Label16.Text = unpaid_comission.Text.ToString();

    TMObj.sponcorid = sponcorid.Text.ToString();
    TMObj.leftcount = leftcount.Text.ToString();
    TMObj.rightcount = rightcount.Text.ToString();
    TMObj.totcount = totcount.Text.ToString();
    TMObj.pair = pair.Text.ToString();
    TMObj.tot_comission = tot_comission.ToString();
    TMObj.paid_comission = paid_comission.ToString();
    TMObj.unpaid_comission = unpaid_comission.ToString();

    dt = DAL.TestCounter_Master.ViewData(TMObj);

    GridView2.DataSource = dt;
    GridView2.DataBind();
    MultiView1.ActiveViewIndex = 3;


}
Posted
Updated 26-Feb-13 19:53pm
v2
Comments
Career Web Helper 27-Feb-13 1:47am    
This will not fire at page_load as to load your gridview the page_load event must be fired i.e.gv will display after page load.This ItemCommand will be fired on any operation done in GridView...
You can do one thing check for IsPagePostback and then call function in that blok...

C#
protected void btnReport_Click(object sender, EventArgs e)
{
    gvUserInfo_ItemCommand(sender, e);
}
 
Share this answer
 
v2
Page load event is a part of Page lifecycle event. You can not fire that event. ASP.net framework do it when request come to WebForm(page). You can call Page Load event handler like
C#
Page_Load(null, EventArgs.Empty);

But it is not recommended approach. You can write a common function/helper method which you want to call/execute from 2 or more different event handlers.
 
Share this answer
 
you can locate this codes into a method and invoke it when you need it! in gvUserInfo_ItemCommand and in Page_Load !
another way is you call this event like this :
C#
ListViewCommandEventArgs l = new ListViewCommandEventArgs(
           new ListViewItem(ListViewItemType.InsertItem),
           listview1,
           new CommandEventArgs("command name",listview1));
gvUserInfo_ItemCommand(sender, l);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900