//第一種 方式
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;
}
}