1

次のようなストアド プロシージャがあります。

ALTER procedure [dbo].[fetchkey]
@carid nvarchar(50) =null
as
begin
 select t.TBarcode, t.Status,[dbo].[keyloc](t.status,@carid) as 'keylocation'
 from Transaction_tbl t 
 where t.TBarcode=@carid
end

また、私はこのような機能を持っています:

ALTER function [dbo].[keyloc](@status numeric(18,2),@cardID VARCHAR(50)) RETURNS varchar(50)
as 
begin 
  @Ename nvarchar(50)
 , @keylocation  Varchar(50)

 if @status=0 
begin 
 select @keylocation= 0 
end
 return @keylocation
end

ストアド プロシージャを実行しているときに、次のように出力されます。

TBarcode             Status      keylocation
53012364813          0             0

このデータをデータグリッドビューに直接入力しています。ここで私のvb.netコード

Dim cmd As New SqlCommand("fetchkey", con.connect) 
cmd.CommandType = CommandType.StoredProcedure 
cmd.Parameters.Add("@carid", SqlDbType.Int).Value = carid     
da.SelectCommand = cmd
da.Fill(ds)
DGVDashBoard.DataSource = ds.Tables(0).    

このようにバインドすると、データ グリッドビューで 3 列が表示されます。データ グリッド ビューでは、Tbarcode 値とステータス値のみを表示したいです。どうすればこれを達成できますか。方法を知っている人がいれば、助けてください。

4

1 に答える 1

1

グリッド ビューの html が表示されないので、アドバイスしかできません。

データセットの一部の列だけを使用し、条件付き書式を設定する場合は、Girdview のRowDataBoundイベントで何らかの処理を行う必要があります。

私はこれを提案します:

    Protected Sub YourGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles YourGridView.RowDataBound
        Dim row As GridViewRow = e.Row
        Dim currentRow As System.Data.DataRow = CType(row.DataItem, System.Data.DataRow)

        If row.RowType = DataControlRowType.DataRow Then
            If currentRow("keylocation") = 0 Then
                row.Style.Add("background", "red")
                row.Style.Add("color", "white")
            End If

            CType(row.FindControl("TBarcodeLabel"), Label).Text = currentRow("TBarcode")
            CType(row.FindControl("StatusLabel"), Label).Text = currentRow("Status")
        End If
    End Sub

Labelこのコードは、入力可能な行テンプレートのどこかに2 つのコントロールが追加されたグリッド ビューがあることを前提としています。

次のようになります。

<asp:GridView ID="YourGridView" runat="server">
    <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50">
        <ItemTemplate>
            <asp:Label ID="TBarcodeLabel" runat="server"></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50">
        <ItemTemplate>
            <asp:Label ID="StatusLabel" runat="server"></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
</asp:GridView>

このようにして、行の人口を処理しているため、列の削除など、行に対して必要な書式設定を行うことができます。

于 2013-07-25T14:41:15.353 に答える