我想在aspx页面上添加列,并且值来自不同的查询,
这是我在aspx上的datagridview:
<asp:Panel ID="pnlGrid" runat="server" align="center">
<asp:Label ID="lbldgTime" runat="server" Text=" "></asp:Label><br />
<asp:GridView ID="gvData" runat="server" AllowPaging="True" AutoGenerateColumns="False"
EmptyDataText="No data available." CellPadding="4" DataKeyNames="PayId" Font-Size="13px"
ForeColor="Black" PageSize="20" Width="100%" Style="text-align: center">
<Columns>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Center" Width="20px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:ImageButton ID="imgbtn" ImageUrl="~/Img/view.png" runat="server" Width="25"
Height="25" OnClick="imgbtn_Click" />
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No Account">
<ItemStyle HorizontalAlign="Center" Width="100px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblNoaccount" runat="server" Text='<%# Bind("PayAccount") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer Name">
<ItemStyle HorizontalAlign="Center" Width="150px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblCustName" runat="server" Text='<%# Bind("PayCustName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemStyle HorizontalAlign="Center" Width="20px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblAmount" runat="server" Text='<%# Bind("PayAmount") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount Paid">
<ItemStyle HorizontalAlign="Center" Width="40px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblRefNo" runat="server" Text='<%# Bind("PayRefNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Response">
<ItemStyle HorizontalAlign="Center" Width="70px" />
<FooterStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblResponse" runat="server" Text='<%# Bind("PayResponse") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
字段:
<asp:TemplateField HeaderText="Response">
<ItemStyle HorizontalAlign="Center" Width="70px" />
<FooterStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblResponse" runat="server" Text='<%# Bind("PayResponse") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
填充数据网格时,该值来自不同的查询,
这是我的datagrid背后的代码:
Sub FillData()
Try
Dim dt As New DataTable
Me.lbleMessage.Text = ""
If txtDate.Text = "__/__/____" Then
txtDate.Text = ""
End If
If CPayment.SearchPayment(txtAccount.Text.Trim, txtCustName.Text.Trim, txtAmount.Text, txtAmountPaid.Text, dropResponse.SelectedValue.ToString, txtRefNo.Text.Trim, txtDate.Text) Then
dt = CPayment.DT
Else
eMessage("System failure: ", CPayment.eMsg)
End If
Dim RC As Integer = dt.Rows.Count
totalrows = RC
If RC = 0 Then
'dt.Rows.Add()
dt.Clear()
gvData.DataSource = dt.DefaultView
gvData.DataBind()
eMessage("", "There are no row to display.")
Else
gvData.DataSource = dt.DefaultView
gvData.DataBind()
gvData.BottomPagerRow.Visible = True
End If
Catch ex As Exception
eMessage("Load Data failure: ", ex.ToString())
End Try
End Sub
这是响应字段的查询:
Public Function Revstatus(ByVal PayRefNo As String) As Boolean
Dim strsql As String = " Select COUNT(*) from payment(Pay) inner(Join) Reversal(Rev) on Pay.PayRefNo = Rev.PayRefNo where Pay.PayRefNo ='%" & PayResponse & "%'"
Return runQuery(strsql)
End Function
ByVal PayRefNo As String
参数来自
<asp:TemplateField HeaderText="Amount Paid">
<ItemStyle HorizontalAlign="Center" Width="40px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblRefNo" runat="server" Text='<%# Bind("PayRefNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
是否可以在填充数据网格时输入不同的查询?
答案 0 :(得分:0)
啊......最后我找到了路。
在datagridview行绑定我做了这个:
If e.Row.RowType = DataControlRowType.DataRow Then
Dim RefNo As Label = CType(e.Row.FindControl("lblRefNo"), Label)
If CPayment.Revstatus(RefNo.Text) Then
CType(e.Row.FindControl("lblRevResp"), Label).Text = "Reversed"
Else
CType(e.Row.FindControl("lblRevResp"), Label).Text = "Paid"
End If
End If