【发布时间】:2020-09-14 18:06:17
【问题描述】:
如何在另一列下添加一列,以便在进行查询输出时在同一行中有两个输出值?在我的情况下,我想显示 Emp ID 并且在该列下我想显示 Cust ID,以便 GridView 表看起来像这样
Emp ID, Rgst ID, Line #, Disc CD, Auth Emp ID, Orig Prc, Disc Amt, Disc Pct, GL Acc ID
客户 ID
另一个问题是我如何在“Orig Prc”输出的末尾添加一列或标题作为总计并将所有“Orig Prc”总和,以便它可以在与“Orig”相同的列中输出结果中华人民共和国”?所以它可能看起来像这样:
原中华人民共和国
原始 prc 输出
总计
输出是所有原始 prc 输出的总和
这可以用当前方法完成,还是我改变了在 ViewGrid 上输出数据的方法?
这是我当前的代码:
Protected Sub ExecuteButton_Click(sender As Object, e As EventArgs) Handles ExecuteButton.Click
Dim StoreID As Integer
Dim TransID As Integer
Dim RgstID As Integer
Dim dt As DataTable
If Not Integer.TryParse(StoreIDTextbox.Text, StoreID) Then
MsgBox("Invalid input. Please enter both Store ID and Transaction ID.")
Exit Sub
End If
If Not Integer.TryParse(TransactionIDTextbox.Text, TransID) Then
MsgBox("Invalid input. Please enter both Store ID and Transaction ID.")
Exit Sub
End If
Sql.AddParam("@Str_ID", StoreID)
Sql.AddParam("@Tran_ID", TransID)
'Rgst_ID Validation
If RegisterIDTextbox.Text.Length = 0 Then
SQL.AddParam("@Rgst_ID", "")
ElseIf RegisterIDTextbox.Text.Length > 0 Then
RgstID = Integer.Parse(RegisterIDTextbox.Text)
Sql.AddParam("@Rgst_ID", RgstID)
End If
Try
dt = SQL.ExecQuery("Select H.Emp_ID, H.Cust_ID, H.Rgst_ID, D.TRAN_LN_NUM, D.DISC_CD, D.AUTH_EMP_ID, D.ORIG_PRC, D.DISC_AMT, D.DISC_PCT, D.GL_ACCT_ID
From Transaction_Header H
INNER Join LN_Detail L On (H.Str_ID = L.Str_ID And H.Rgst_ID = L.Rgst_ID And H.Tran_ID = L.Tran_ID)
INNER Join LN_Discount D ON (L.Str_ID = D.Str_ID And L.Rgst_ID = D.Rgst_ID And L.Tran_ID = D.Tran_ID And L.Tran_LN_Num = D.Tran_LN_Num)
WHERE(H.Str_ID = @Str_ID)
And (H.Tran_ID = @Tran_ID)
And ((H.Rgst_ID = @Rgst_ID) Or (@Rgst_ID Is NULL Or @Rgst_ID = ''))")
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
GridView2.DataSource = dt
GridView2.DataBind()
TimeLabel.Text = DateAndTime.Now
网格视图
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns ="False" CellPadding="4" ForeColor="#333333">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Emp_ID" HeaderText="Emp ID" />
<asp:BoundField DataField="Cust_ID" HeaderText="Cust ID" />
<asp:BoundField DataField="Rgst_ID" HeaderText="Rgst ID" />
<asp:BoundField DataField="TRAN_LN_NUM" HeaderText="Line #" />
<asp:BoundField DataField="DISC_CD" HeaderText="Disc CD" />
<asp:BoundField DataField="AUTH_EMP_ID" HeaderText="Auth Emp ID" />
<asp:BoundField DataField="ORIG_PRC" HeaderText="Orig Prc" />
<asp:BoundField DataField="Disc_Amt" HeaderText="Disc Amt" />
<asp:BoundField DataField="Disc_Pct" HeaderText="Disc Pct" />
<asp:BoundField DataField="GL_ACCT_ID" HeaderText="GL Acct ID" />
</Columns>
【问题讨论】:
标签: asp.net vb.net web-applications