程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> gridview中彈窗口(根據不同的條件,彈出不同的窗口)

gridview中彈窗口(根據不同的條件,彈出不同的窗口)

編輯:.NET實例教程


//第一種 方式
    protected void RecAmtGridView_SelectedIndexChanging(object sender, GridVIEwSelectEventArgs e)
    {
        string billNo = RecAmtGridVIEw.Rows[e.NewSelectedIndex].Cells[3].Text;
        string billType = RecAmtGridVIEw.Rows[e.NewSelectedIndex].Cells[2].Text;
        if (billType =="進貨")
        {
            Response.Redirect("TS_HqReceiveReg.ASPx?Action=3&fBillNo=" + billNo);
            ScriptManager.RegisterClIEntScriptBlock(this.UpdatePanel1, UpdatePanel1.GetType(), "進貨", "window.open('TS_HqReceiveReg.ASPx?Action=3&fBillNo=" + billNo + "')", true);
        }
        else if (billType == "退貨")
        {
            Response.Redirect("TS_HqReturnReg.ASPx?Action=3&fBillNo=" + billNo);
            ScriptManager.RegisterClIEntScriptBlock(this.UpdatePanel1, UpdatePanel1.GetType(), "進貨", "window.open('TS_HqReturnReg.ASPx?Action=3&fBillNo=" + billNo + "')", true);

        }
        else
        {
            Response.Redirect("CostRegVIEw.ASPx?Action=3&fBillNo=" + billNo);
            ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, UpdatePanel1.GetType(), "進貨", "window.open('CostRegVIEw.ASPx?Action=3&fBillNo=" + billNo + "')", true);

        }

    }

    //第二種方式: 加入模板列
  <ASP:TemplateFIEld HeaderText="單據編號">
     <ItemTemplate>
     <asp:LinkButton ID="lbRecAmtBill" CommandName="lbRecAmtBill"  Text='<%#Eval("fBillNo")%>'  runat="server"></ASP:LinkButton>
     </ItemTemplate>
 </ASP:TemplateFIEld>

    protected void RecAmtGridView_RowCommand(object sender, GridVIEwCommandEventArgs e)
    {
        GridViewRow GridViewRow1 = (GridVIEwRow)((Control)e.CommandSource).Parent.Parent;

        LinkButton lbbutton = GridVIEwRow1.FindControl("lbRecAmtBill") as LinkButton;
        string billNo = lbbutton.Text;
        string billType = Gri
dVIEwRow1.Cells[2].Text;
        if (billType == "進貨")
        {
            ScriptManager.RegisterClIEntScriptBlock(this.UpdatePanel1, UpdatePanel1.GetType(), "進貨", "window.open('TS_HqReceiveReg.ASPx?Action=3&fBillNo=" + billNo + "')", true);
        }
        else if (billType == "退貨")
        {
            ScriptManager.RegisterClIEntScriptBlock(this.UpdatePanel1, UpdatePanel1.GetType(), "退貨", "window.open('TS_HqReturnReg.ASPx?Action=3&fBillNo=" + billNo + "')", true);

        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, UpdatePanel1.GetType(), "費用", "window.open('CostRegVIEw.ASPx?Action=3&fBillNo=" + billNo + "')", true);

        }

    }


    //第三種方式
   <ASP:HyperLinkField HeaderText="單據編號" Text="單據編號"  Target="mainframe" NavigateUrl="" DataTextFIEld="fBillNo" >
   </ASP:HyperLinkFIEld>

    protected void PayAmtGridView_RowDataBound(object sender, GridVIEwRowEventArgs e)
    {

        if (e.Row.RowIndex >= 0)
        {

            sumRealAmt += Convert.ToDouble(e.Row.Cells[3].Text);
            sumDiscAmt += Convert.ToDouble(e.Row.Cells[4].Text);
            sumTotAmt += Convert.ToDouble(e.Row.Cells[5].Text);
            sumInvAmt += Convert.ToDouble(e.Row.Cells[6].Text);

        }
        else if (e.Row.RowType == DataControlRowType.Footer) 每列匯總求和
        {
            e.Row.Cells[2].Text = "總計:";
            e.Row.Cells[3].Text = sumRealAmt.ToString();
            e.Row.Cells[4].Text = sumDiscAmt.ToString();
            e.Row.Cells[5].Text = sumTotAmt.ToString();
            e.Row.Cells[6].Text = sumInvAmt.ToString()



;

        }

        綁定轉向頁面
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            必須將HyperLinkFIEld 轉化為 HyperLink 才能進行操作
            HyperLink linkFIEld = (HyperLink)e.Row.Cells[3].Controls[0];
            billNo = linkFIEld.Text ;
            billType = e.Row.Cells[2].Text;

            if (billType == "進貨")
            {
                 url = "TS_HqReceiveReg.ASPx?Action=3&fBillNo=" + billNo + "";
            }
            else if (billType == "退貨")
            {
                 url = "TS_HqReturnReg.ASPx?Action=3&fBillNo=" + billNo + "";

            }
            else
            {
                 url = "CostRegVIEw.ASPx?Action=3&fBillNo=" + billNo + "";

            }

            linkFIEld.NavigateUrl = url; 
        }

    }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved