简体   繁体   中英

ASP.NET Gridview: How can we find which column was selected in gridview

I have extended the Gridview making it Clickable (ie when ever we click on any row it is selected and a detail view is shown according to the row selected).

I then added Selecting / Deselecting all the CheckBoxes in that GridView with the help of javascript. The problem now is that the page is being postbacked every time i click checkbox. I don't want this i don't want postback to happen if this particular column element ie checkbox is pressed.

Is there any way that i can know which of the column is being selected when when the postback happens so that i can know it is happening form the column having checkbox.

Please let me know if you have soultion to it.

Thanks,

I found the solution for my problem which is as follow:

We have to cancel the Event Bubbling from Checkbox so that it won't bubble up to the Gridview RowClicked event.

The way of canceling the event bubbling form checkbox is as follow:

cb.Attributes("onclick") = "event.cancelBubble=true;"

where cb is the checkbox.

Hope this will help others having same problem as i did,

Thanks,

I'm, not to sure how exactly you add the checkbox to your gridview row but in case you do it server side make sure the AutoPostback property for the (or each) checkbox is set to false. If set to true you'll end up with a postback as soon as somebody checks/unchecks one of your checkboxes.

We can add checkbox in our gridview, below is a sample code that we need inside Columns of GridView:

<asp:TemplateField HeaderText="Select">
<ItemTemplate>
    <asp:CheckBox ID="chkBxSelect" runat="server" AutoPostBack ="false" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<HeaderTemplate>
    <asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
</HeaderTemplate>

Is it possible in ASP.NET Gridview the we postback if we click in some columns of Gridview and we don't postback when we click in certain selected columns.

eg I have 3 columns in a gridview, I want to postback if i click in column 1 and 2 and don't want postback if i click in column 3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM