[英]Select row should not include the first column datagridview asp.net
I would like the select rowdatabound not to included the first colunm. 我希望select rowdatabound不包含第一个栏。 The reason for it is when i click on expand the datagridview the page refreshes causing the datagridview row to collapse again. 原因是当我单击扩展datagridview时页面刷新,导致datagridview行再次折叠。
Here is a image of my table I have circuled in red the column I would like to remove from the rowdatabound. 这是我的表的图像,我用红色圈出了我要从rowdatabound中删除的列。
Here is my code for OnRowDataBound 这是我的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.";
}
}
And here is my aspx code: 这是我的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>
I would like the first column not to be included in rowdatabound. 我希望第一列不包含在rowdatabound中。
Instead of adding the onclick
to a row you could add it to each cell individually and skip the first cell. 您可以将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.";
}
}
Or add a class name tot the first cell in the RowDataBound
or ItemStyle-CssClass
in the aspx. 或将类名添加到aspx的RowDataBound
或ItemStyle-CssClass
的第一个单元格中。
e.Row.Cells[0].Attributes["class"] = "noClick";
Then use jquery to prevent the clicking. 然后使用jquery防止单击。
$('.noClick').click(function (e) {
e.stopPropagation();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.