У меня есть два столбца для каждого столбца. Я хочу удалить все столбцы BoundField и сохранить столбцы TemplateField.Я следовал инструкции на этом сайте https://www.aspsnippets.com/Articles/GridView-with-CheckBox-Get-Selected-Rows-in-ASPNet.aspx, но у меня уже была таблица, но с TemplateField и BoundField.Я хочу иметь возможность использовать мою старую таблицу и удалить boundField из моей таблицы.
Вот изображение того, что я хочу удалить красным.
Вот где моя таблица выглядит так:
<asp:GridView ID="gvPrimaryGrid" runat="server" AutoGenerateColumns="false" ShowFooter="true" onrowdatabound="gvPrimaryGrid_RowDataBound"
ShowHeaderWhenEmpty="true" AllowPaging="True" OnPageIndexChanging="gridView_PageIndexChanging" DataKeyNames="compras_id"
OnRowCommand="gvPrimaryGrid_RowCommand" OnRowEditing="gvPrimaryGrid_RowEditing" OnRowCancelingEdit="gvPrimaryGrid_RowCancelingEdit"
OnRowUpdating="gvPrimaryGrid_RowUpdating" CellPadding="3" AllowUserToResizeColumns="True" PageSize="5" AllowSorting="true" onsorting="gvPrimaryGrid_Sorting" GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
<PagerSettings Mode="Numeric" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%--<asp:CheckBox ID="CheckBox1" AutoPostBack="true" EnableViewState="true" runat="server" onclick="Check_Click(this)" OnCheckedChanged="chkRow_CheckChanged" />--%>
<asp:CheckBox ID="chkRow" AutoPostBack="true" runat="server" OnCheckedChanged="chkRow_CheckChanged" />
<%--<asp:CheckBox ID="chkRow" runat="server" />--%>
<asp:ImageButton ImageUrl="~/Images/edit.png" runat="server" CommandName="Edit" ToolTip="Edit" Width="20px" Height="20px"/>
<asp:ImageButton ImageUrl="~/Images/delete.png" runat="server" CommandName="Delete" ToolTip="Delete" Width="20px" Height="20px"/>
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ImageUrl="~/Images/save.png" runat="server" CommandName="Update" ToolTip="Update" Width="20px" Height="20px"/>
<asp:ImageButton ImageUrl="~/Images/cancel.png" runat="server" CommandName="Cancel" ToolTip="Cancel" Width="20px" Height="20px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:ImageButton ImageUrl="~/Images/addnew.png" runat="server" CommandName="AddNew" ToolTip="Add New" Width="20px" Height="20px"/>
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField = "compras_id" HeaderText="Compras ID" HtmlEncode="false" />
<asp:BoundField DataField = "numero_contrato" HeaderText = "Numero contrato" HtmlEncode="false" />
<asp:BoundField DataField="marca" HeaderText="Marca" HtmlEncode="false" />
<asp:BoundField DataField="designacion" HeaderText="Designacion" HtmlEncode="false" />
<asp:BoundField DataField="tipo" HeaderText="Tipo" HtmlEncode="false" />
<asp:BoundField DataField="referencia" HeaderText="Referencia" HtmlEncode="false" />
<asp:BoundField DataField="plazo" HeaderText="Plazo" HtmlEncode="false" />
<asp:BoundField DataField="nombre_proveedor" HeaderText="Proveedor" HtmlEncode="false" />
<asp:BoundField DataField="cantidad_requerida" HeaderText="Cantidad requerida" HtmlEncode="false"/>
<asp:BoundField DataField="cantidad_pedida" HeaderText="Cantidad pedida" HtmlEncode="false"/>
<asp:TemplateField HeaderText="Compras ID" SortExpression="compras_id" Visible="false">
<ItemTemplate>
<asp:Label DataField="compras_id" HtmlEncode="false" ID="lblPurschaseID" CssClass="gridTextbox" Text='<%# Eval("compras_id") %>' runat="server" />
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox CssClass="gridTextbox" ID="txtType" Text='<%# Eval("tipo") %>' runat="server" />
</EditItemTemplate>--%>
<FooterTemplate>
<asp:TextBox CssClass="gridTextbox" ID="txtPurschaseIDFooter" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Numero contrato" >
<ItemTemplate>
<asp:Label DataField="numero_contrato" HtmlEncode="false" ID="lblContractNumber" CssClass="gridTextbox" Text='<%# Eval("numero_contrato") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="drGridContractID" Runat="server" AutoPostBack="false" OnSelectedIndexChanged="DropDown_SelectedIndexChanged" />
<%-- <asp:TextBox CssClass="gridTextbox" ID="txtSupplier" Text='<%# Eval("nombre_proveedor") %>' runat="server" />--%>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox CssClass="gridTextbox" ID="txtContractNumberFooter" runat="server" />
</FooterTemplate>
</asp:TemplateField>
Я хочу изменить строку AddRow и Remove, чтобы она работала с полем шаблона вместо BoundField
private DataTable AddRow(GridViewRow gvRow, DataTable dt)
{
// gvRow.Cells[1].Text
DataRow[] dr = dt.Select("compras_id = '" + gvPrimaryGrid.Rows[0].Cells[1].Text+ "'");
if (dr.Length <= 0)
{
int i = 1;
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["compras_id"] = gvRow.Cells[i++].Text;
dt.Rows[dt.Rows.Count - 1]["numero_contrato"] = gvRow.Cells[i++].Text;
dt.Rows[dt.Rows.Count - 1]["marca"] = gvRow.Cells[i++].Text;
dt.Rows[dt.Rows.Count - 1]["designacion"] = gvRow.Cells[i++].Text;
dt.Rows[dt.Rows.Count - 1]["tipo"] = gvRow.Cells[i++].Text;
dt.Rows[dt.Rows.Count - 1]["referencia"] = gvRow.Cells[i++].Text;
dt.Rows[dt.Rows.Count - 1]["plazo"] = gvRow.Cells[i++].Text;
dt.Rows[dt.Rows.Count - 1]["nombre_proveedor"] = gvRow.Cells[i++].Text;
//dt.Rows[dt.Rows.Count - 1]["cantidad_requerida"] = gvRow.Cells[i++].Text;
dt.Rows[dt.Rows.Count - 1]["cantidad_pedida"] = gvRow.Cells[i++].Text;
dt.Rows[dt.Rows.Count - 1]["cantidad_entregada"] = gvRow.Cells[i++].Text;
dt.AcceptChanges();
}
return dt;
}
private DataTable RemoveRow(GridViewRow gvRow, DataTable dt)
{
DataRow[] dr = dt.Select("compras_id = '" + gvRow.Cells[1].Text + "'");
if (dr.Length > 0)
{
dt.Rows.Remove(dr[0]);
dt.AcceptChanges();
}
return dt;
}