2017-05-18 10 views
0

GridViewがあります。CheckBoxはステータス(列名)= 'sent'の行のみに表示されます。GridViewのCheckBoxを動的に表示する方法は?

のaspx

<asp:GridView ID="gvPOItems" runat="server" AutoGenerateColumns="False" 
Width="100%" role="grid" aria-describedby="example_info"> 
<Columns> 
<asp:BoundField DataField="ItemNumber" HeaderText="Row Number" ItemStyle-CssClass="hide" 
    HeaderStyle-CssClass="hide" /> 
<asp:TemplateField HeaderText="Cancel SO Line Item"> 
    <ItemTemplate> 
<asp:checkbox ID="cbSOCan" runat="server"></asp:checkbox> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField HeaderText="Description"> 
<ItemTemplate> 
<asp:TextBox ID="txtDesc" CssClass="form-control grid-textbox-big" MaxLength="200" 
runat="server"></asp:TextBox> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField HeaderText="Quantity"> 
<ItemTemplate> 
<asp:TextBox ID="txtQuantity" CssClass="form-control grid-textbox-small" runat="server"></asp:TextBox> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField HeaderText="Unit $"> 
<ItemTemplate> 
<asp:TextBox ID="txtUnitPrice" CssClass="form-control grid-textbox-small" runat="server"></asp:TextBox> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField HeaderText="Total $"> 
    <ItemTemplate> 
<asp:TextBox ID="txtTotal" Enabled="false" CssClass="form-control grid-textbox-small" runat="server"></asp:TextBox> 
    </ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField HeaderText="Account Code"> 
    <ItemTemplate> 
<div class="grid-code-tbl"> 
<asp:Label ID="lblAccountCode" Text='<%# Eval("ACCTNUM") %>' Visible="false" runat="server"></asp:Label> 
<asp:Label ID="lblACCTNUMDesc" Text='<%# Eval("ACCTNUMDesc") %>' CssClass="grid-code-cell form-control" runat="server"></asp:Label> 
<asp:Label ID="lblIsCAPEXJOBCODE" runat="server" Text='<%# Eval("IsCAPEXJOBCODE") %>' Visible="false"></asp:Label> 
<div class="grid-code-cell grid-code-icon" runat="server" id="AccountCodeDiv"> 
<asp:LinkButton ID="lnkAccountCode" CssClass="btn btn-default" CommandName="SelectAccountCode" runat="server"><i class="fa fa-th-list"></i></asp:LinkButton></div> 
</div> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField HeaderText="Tax ID"> 
<ItemTemplate> 
<asp:DropDownList ID="ddlTaxID" runat="server" CssClass="form-control grid-textbox-small"> 
    </asp:DropDownList> 
</ItemTemplate> 
    </asp:TemplateField> 
<asp:TemplateField HeaderText="Status"> 
    <ItemTemplate> 
    <asp:checkbox ID="cbSOCan" CssClass="gridCB" runat="server" Visible='<%# (Eval("StatusFieldName").ToString() == "Sent")%>'></asp:checkbox></asp:Label> 
</ItemTemplate> 
</asp:TemplateField> 
    <asp:TemplateField HeaderText="From Date"> 
    <ItemTemplate> 
    <div class="input-group grid-datebox"> 
    <asp:TextBox ID="txtFromDate" runat="server" MaxLength="10" placeholder="DD/MM/YYYY" CssClass="form-control"></asp:TextBox> 
<span class="input-group-addon calendar-icon" id="FromCalSpan"><i class="fa fa-calendar"> 
</i></span> 
    </div> 
</ItemTemplate> 
</asp:TemplateField> 
    <asp:TemplateField HeaderText="To Date"> 
    <ItemTemplate> 
<div class="input-group grid-datebox"> 
    <asp:TextBox ID="txtToDate" runat="server" MaxLength="10" placeholder="DD/MM/YYYY" CssClass="form-control"></asp:TextBox> 
    <span class="input-group-addon calendar-icon" id="ToCalSpan"><i class="fa fa-calendar"> </i></span> 
</div> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField HeaderText="Capital Project (Optional)"> 
    <ItemTemplate> 
<div class="grid-code-tbl"> 
    <asp:Label ID="lblJobCode" CssClass="grid-code-cell form-control" Text='<%# Eval("JOBCODE") %>'runat="server"></asp:Label> 
<div class="grid-code-cell grid-code-icon" runat="server" id="JobCodeDiv"> 
<asp:LinkButton ID="lnkJobCode" CommandName="SelectJobCode" runat="server" class="btn btn-default"><i class="fa fa-th-list"></i></asp:LinkButton></div> 
</div> 
    </ItemTemplate> 
    </asp:TemplateField> 
<asp:TemplateField HeaderText="Invoice Number"> 
<ItemTemplate> 
    <asp:TextBox CssClass="form-control hiddenElm" ID="txtInvoiceNumber" onblur="SetInvoiceNumber(this.value);" 
Text='<%# Eval("InvoiceNumber") %>' runat="server"></asp:TextBox> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:BoundField DataField="HISTSTATUS" HeaderText="Payment Status" /> 
<asp:BoundField DataField="HISTCHECKDT" HeaderText="Date Paid" DataFormatString="{0:dd/MM/yyyy}" /> 
    <asp:BoundField DataField="HISTFRIDNO" HeaderText="Funds Request#" /> 
<asp:BoundField DataField="HISTFRIDNO" HeaderText="Attachment" /> 
</Columns> 
</asp:GridView> 

コード

Protected Sub btnCancelItem_Click(sender As Object, e As EventArgs) Handles btnCancelItem.Click 
    For Each gvrow As GridViewRow In gvPOItems.Rows 
     Dim chkdelte As CheckBox = DirectCast(gvrow.FindControl("cbSOCan"), CheckBox) 
     If chkdelte.Checked Then 
      ' gvAdditionalArea.Rows(rowIndex).Cells(0).Text() 
      Dim ItemNumber As Int32 = Convert.ToInt32(gvrow.Cells(0).Text()) 
      Queries.CancelSOlineItem(ItemNumber, txtPONumber.Text) 
      gvrow.Cells(0).Text() = "Cancelled" 
     End If 
    Next 
    ' gvPOItems.DataBind() 
End Sub 

Protected Sub gvPOItems_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvPOItems.RowDataBound 
    Dim lblStatus As Label = DirectCast(e.Row.FindControl("lblStatus"), Label) 
    If lblStatus.Text = "Sent" Then 
     e.Row.Cells(1).Visible = True 
    Else 
     e.Row.Cells(1).Visible = False 
    End If 
End Sub 

grid

答えて

0

あなたはすでにテーブルを移入するために持っていた値を使用してこれを行うことができます。

<asp:templatefield HeaderText="Cancel SO Line Item"> 
    <itemtemplate> 
     <asp:checkbox ID="cbSOCan" CssClass="gridCB" runat="server" Visible='<%# (Eval("StatusFieldName").ToString() == "Sent")%>'></asp:checkbox> 
    </itemtemplate> 
</asp:templatefield> 


EDIT ....

私はStatusFieldNameを置くとき、私は、フィールドの名前を必要としていました。エラーが来

<asp:GridView ID="gvPOItems" runat="server" AutoGenerateColumns="False" Width="100%" role="grid" aria-describedby="example_info"> 
<Columns> 
    <asp:BoundField DataField="ItemNumber" HeaderText="Row Number" ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" /> 
    <asp:TemplateField HeaderText="Cancel SO Line Item"> 
     <ItemTemplate> 
      <asp:checkbox ID="cbSOCan" runat="server"></asp:checkbox> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Description"> 
     <ItemTemplate> 
      <asp:TextBox ID="txtDesc" CssClass="form-control grid-textbox-big" MaxLength="200" runat="server"></asp:TextBox> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Quantity"> 
     <ItemTemplate> 
      <asp:TextBox ID="txtQuantity" CssClass="form-control grid-textbox-small" runat="server"></asp:TextBox> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Unit $"> 
     <ItemTemplate> 
      <asp:TextBox ID="txtUnitPrice" CssClass="form-control grid-textbox-small" runat="server"></asp:TextBox> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Total $"> 
     <ItemTemplate> 
      <asp:TextBox ID="txtTotal" Enabled="false" CssClass="form-control grid-textbox-small" runat="server"></asp:TextBox> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Account Code"> 
     <ItemTemplate> 
      <div class="grid-code-tbl"> 
       <asp:Label ID="lblAccountCode" Text='<%# Eval("ACCTNUM") %>' Visible="false" runat="server"></asp:Label> 
       <asp:Label ID="lblACCTNUMDesc" Text='<%# Eval("ACCTNUMDesc") %>' CssClass="grid-code-cell form-control" runat="server"></asp:Label> 
       <asp:Label ID="lblIsCAPEXJOBCODE" runat="server" Text='<%# Eval("IsCAPEXJOBCODE") %>' Visible="false"></asp:Label> 
       <div class="grid-code-cell grid-code-icon" runat="server" id="AccountCodeDiv"> 
        <asp:LinkButton ID="lnkAccountCode" CssClass="btn btn-default" CommandName="SelectAccountCode" runat="server"><i class="fa fa-th-list"></i></asp:LinkButton> 
       </div> 
      </div> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Tax ID"> 
     <ItemTemplate> 
      <asp:DropDownList ID="ddlTaxID" runat="server" CssClass="form-control grid-textbox-small"></asp:DropDownList> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Status"> 
     <ItemTemplate> 
      <asp:checkbox ID="cbSOCan" CssClass="gridCB" runat="server" Visible='<%# (Eval("HISTSTATUS").ToString() IS "Sent")%>'></asp:checkbox></asp:Label> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="From Date"> 
     <ItemTemplate> 
      <div class="input-group grid-datebox"> 
       <asp:TextBox ID="txtFromDate" runat="server" MaxLength="10" placeholder="DD/MM/YYYY" CssClass="form-control"></asp:TextBox> 
       <span class="input-group-addon calendar-icon" id="FromCalSpan"><i class="fa fa-calendar"></i></span> 
      </div> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="To Date"> 
     <ItemTemplate> 
      <div class="input-group grid-datebox"> 
       <asp:TextBox ID="txtToDate" runat="server" MaxLength="10" placeholder="DD/MM/YYYY" CssClass="form-control"></asp:TextBox> 
       <span class="input-group-addon calendar-icon" id="ToCalSpan"><i class="fa fa-calendar"> </i></span> 
      </div> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Capital Project (Optional)"> 
     <ItemTemplate> 
      <div class="grid-code-tbl"> 
       <asp:Label ID="lblJobCode" CssClass="grid-code-cell form-control" Text='<%# Eval("JOBCODE") %>'runat="server"></asp:Label> 
       <div class="grid-code-cell grid-code-icon" runat="server" id="JobCodeDiv"> 
        <asp:LinkButton ID="lnkJobCode" CommandName="SelectJobCode" runat="server" class="btn btn-default"><i class="fa fa-th-list"></i></asp:LinkButton> 
       </div> 
      </div> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Invoice Number"> 
     <ItemTemplate> 
      <asp:TextBox CssClass="form-control hiddenElm" ID="txtInvoiceNumber" onblur="SetInvoiceNumber(this.value);" Text='<%# Eval("InvoiceNumber") %>' runat="server"></asp:TextBox> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:BoundField DataField="HISTSTATUS" HeaderText="Payment Status" /> 
    <asp:BoundField DataField="HISTCHECKDT" HeaderText="Date Paid" DataFormatString="{0:dd/MM/yyyy}" /> 
    <asp:BoundField DataField="HISTFRIDNO" HeaderText="Funds Request#" /> 
    <asp:BoundField DataField="HISTFRIDNO" HeaderText="Attachment" /> 
</Columns> 

+0

エラーは、この要求を処理するために必要なリソースのコンパイル中に発生しました。以下の特定のエラーの詳細を確認し、ソースコードを適切に変更してください。 –

+0

あなたの質問にすべてのgridviewマークアップを入れることができますか?それが返されたエラーテキストは何でしたか? –

+0

コード・エラーを更新しました。**この要求を処理するために必要なリソースのコンパイル中にエラーが発生しました。以下の特定のエラーの詳細を確認し、ソースコードを適切に変更してください。** –

関連する問題