• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 682
  • Last Modified:

load gridview on label click

Hi,
I have gridview on web page.  there are two labels (coded appended below). I need to pass value on click "Free Stock=0" and on click "Purchased=0"  and re-load grid according to the parameter after getting data to the database.



   <div>
        <span style="width:400px; text-align:left; ">
        <a href="InvPage.aspx" id="lbFreeStock">  Free Stock </a>
        </span>
        <span style="width:400px; text-align:left;" >
        <a href="InvPage.aspx" id="lbPurchasedStock"> Purchased Stock </a>
        </span>    
        <span style="width:400px; text-align:left;" >
        <a href="InvPageAdd.aspx" id="lbAddNew" > Add New </a>
        </span>    
    </div>


        private void loadGrid()
        {
             string values = "Select sno=Row_number() Over (Order by InvNo,Date), Date, InvNo, Amt=Sum(Amt), CoCom=Sum(Isnull(CoCom,0)), MkCom=Sum(Isnull(MkCom,0)), NPV=Sum(NetPurchasedValue), FreeStock from tempp Where FreeStock='0' Group by Date, InvNo, FreeStock Order by InvNo,Date";
               
            using (con = new SqlConnection(ConfigurationManager.ConnectionStrings["DLICCBPL"].ConnectionString))
            {
                cmd = new SqlCommand(values,con);
                con.Open();                
                ds = new DataSet();
                da = new SqlDataAdapter(cmd);
                da.Fill(ds,"bb");
                Invoicing.DataSource = ds;
                Invoicing.DataMember = "bb";                
                Invoicing.DataBind();
                con.Close();
            }
        }
0
Mehram
Asked:
Mehram
  • 4
  • 3
1 Solution
 
MehramAuthor Commented:
Page pic

page
0
 
informaniacCommented:
Try using the LinkButton Control.
0
 
informaniacCommented:
<asp:LinkButton ID="lnk1" runat="server" Text="Free" 
            onclick="lnk1_Click"></asp:LinkButton>

protected void lnk1_Click(object sender, EventArgs e)
        {
                 loadGrid(0);
        }

private void loadGrid(int iArg)
{

}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MehramAuthor Commented:
Sir, in that case how to pass values on page IndexChanging:

    protected void Invoicing_PageIndexChanging(Object sender, GridViewPageEventArgs e)
        {
            Invoicing.PageIndex = e.NewPageIndex;
            loadGrid();
            //((GridView)sender).PageIndex = e.NewPageIndex;
           
        }

I did with sql statement like this to handle where statement.

string values;
            switch (iArg)
            {
                case 1:
                    values = "Select sno=Row_number() Over (Order by InvNo,Date), Date, InvNo, Amt=Sum(Amt), CoCom=Sum(Isnull(CoCom,0)), MkCom=Sum(Isnull(MkCom,0)), NPV=Sum(NetPurchasedValue), FreeStock from tempp Where FreeStock='1' Group by Date, InvNo, FreeStock Order by InvNo,Date";
                    break;
                default:
                    values = "Select sno=Row_number() Over (Order by InvNo,Date), Date, InvNo, Amt=Sum(Amt), CoCom=Sum(Isnull(CoCom,0)), MkCom=Sum(Isnull(MkCom,0)), NPV=Sum(NetPurchasedValue), FreeStock from tempp Where FreeStock='0' Group by Date, InvNo, FreeStock Order by InvNo,Date";
                    break;
            }
            using (con = new SqlConnection(ConfigurationManager.ConnectionStrings["DLICCBPL"].ConnectionString))............................
0
 
informaniacCommented:
Hmm. In that case you will hav to save the value in a viewstate variable.

protected void lnk1_Click(object sender, EventArgs e)
        {
               ViewState["SortNo"] = 0;   
               loadGrid();
        }

private void loadGrid()
{
            if(ViewState["SortNo"] != null)
            int iArg = Convert.ToInt32(ViewState["SortNo"]);
}

Open in new window

0
 
MehramAuthor Commented:
It has started working. but carrying a little bug.
Page load by default with 0 value to show all purchased record
on click any page on gridview page link it is showing properly.
For example I am now on page number 5 and suddenly clicked on free link then the gridview load free stock detail properly but display page no 5 directly instead of that start from page # 1.
The same think happened when I come from free purchase. Not start to page no one.
0
 
MehramAuthor Commented:
my page code is as follows:

namespace CCBPL_InvPage
{
    public partial class InvPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
           
                ViewState["SortNo"] = 0; //To load Purchased Invoices by default
                loadGrid();
           
        }
        SqlConnection con;
        SqlCommand cmd;
        DataSet ds;
        SqlDataAdapter da;
        int iArg;
        private void loadGrid()
        {
            if (ViewState["SortNo"] != null)
            {
                iArg = Convert.ToInt32(ViewState["SortNo"]);
                using (con = new SqlConnection(ConfigurationManager.ConnectionStrings["DLICCBPL"].ConnectionString))
                {
                    string values = "Select sno=Row_number() Over (Order by InvNo,Date), Date, InvNo, Amt=Sum(Amt), CoCom=Sum(Isnull(CoCom,0)), MkCom=Sum(Isnull(MkCom,0)), NPV=Sum(NetPurchasedValue), FreeStock from tempp Where FreeStock='" + iArg + "' Group by Date, InvNo, FreeStock Order by InvNo,Date";
                    cmd = new SqlCommand(values, con);
                    con.Open();
                    ds = new DataSet();
                    da = new SqlDataAdapter(cmd);
                    da.Fill(ds, "bb");
                    Invoicing.DataSource = ds;
                    Invoicing.DataMember = "bb";
                    Invoicing.DataBind();
                    con.Close();
                }
            }
            else
            {
                //need to display message
            }
           
        }
      protected void Invoicing_PageIndexChanging(Object sender, GridViewPageEventArgs e)
        {
            Invoicing.PageIndex = e.NewPageIndex;
            loadGrid();
            //((GridVi0ew)sender).PageIndex = e.NewPageIndex;  
        }
      protected void lnk1_Click(object sender, EventArgs e)
        {
            ViewState["SortNo"] = 1;
            loadGrid();
        }
      protected void lnk2_Click(object sender, EventArgs e)
      {
          ViewState["SortNo"] = 0;
          loadGrid();
      }
    }
}
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now