[英]Select row should not include the first column datagridview asp.net
我希望select rowdatabound不包含第一個欄。 原因是當我單擊擴展datagridview時頁面刷新,導致datagridview行再次折疊。
這是我的表的圖像,我用紅色圈出了我要從rowdatabound中刪除的列。
這是我的OnRowDataBound代碼
protected void OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvInventario, "Select$" + e.Row.RowIndex);
e.Row.ToolTip = "Haga clic para seleccionar esta fila.";
}
}
這是我的aspx代碼:
<asp:GridView ID="gvInventario" runat="server" AutoGenerateColumns="false" AllowSorting="true" ShowFooter="false" DataKeyNames="componente_id, ubicacion_id"
ShowHeaderWhenEmpty="true" AllowPaging="True" OnPageIndexChanging="gridView_PageIndexChanging" OnRowDataBound = "OnRowDataBound" OnSelectedIndexChanged = "OnSelectedIndexChanged"
CellPadding="3" AllowColumResize="True" onsorting="grdDetails_Sorting" GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate >
<a href="JavaScript:divexpandcollapse('div<%# Eval("componente_id") %>');" >
<img id="imgdiv<%# Eval("componente_id") %>" width="9px" border="0" src="../images/plus.gif"
alt="" /></a>
</ItemTemplate>
<ItemStyle Width="20px" VerticalAlign="Middle"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Min" SortExpression="cantidad_mini">
<ItemTemplate>
<asp:Label Text='<%# Eval("cantidad_mini") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtQuantityMin" Text='<%# Eval("cantidad_mini") %>' runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我希望第一列不包含在rowdatabound中。
您可以將onclick
單獨添加到每個單元格中,而無需跳過第一個單元格,而無需將onclick
添加到行中。
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 1; i < e.Row.Cells.Count; i++)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvInventario, "Select$" + e.Row.RowIndex);
e.Row.ToolTip = "Haga clic para seleccionar esta fila.";
}
}
或將類名添加到aspx的RowDataBound
或ItemStyle-CssClass
的第一個單元格中。
e.Row.Cells[0].Attributes["class"] = "noClick";
然后使用jquery防止單擊。
$('.noClick').click(function (e) {
e.stopPropagation();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.