//第一種 方式
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 = GridViewRow1.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;
}
}
新聞熱點
疑難解答