views:

405

answers:

3

I have extended the Gridview making it Clickable (i.e. 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 i.e 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,

A: 

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.

Flo
A: 

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.

e.g. 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.

prsthapit
+1  A: 

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,

prsthapit