I have a a Gridview which displays records (training) of various individuals! When you click on the various cells an AJAX ModelPopUpextender opens showing further details relating to that particular training sets!
The problem I'm having is that when I click on any of the GridView cells and the ModelPopUp opens the Gridview PostsBack. Id like to be able to click on any cell and get the same functinality without the Gridview posting back?
<asp:GridView ID="GridView1" runat="server" CssClass="rounded-corner" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand" DataKeyNames="setName" AutoGenerateColumns="true" ><Columns> <asp:buttonfield commandname="CellClick" runat="server" visible="false"></asp:buttonfield> </Columns></asp:GridView><asp:Button runat="server" ID="btnShowModalPopup" Style="display: none" /><ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowModalPopup" PopupControlID="divPopUp" PopupDragHandleControlID="panelDragHandle" DropShadow="False" /><br /><div class="popUpStyle2" id="divPopUp" style="display: none;"><asp:Panel runat="Server" ID="panelDragHandle" CssClass="drag"> Hold here to Drag this Box</asp:Panel><asp:DetailsView ID="DetailsView1" runat="server" Height="100%" Width="220px" BorderStyle="None" DefaultMode="ReadOnly" GridLines="None" AutoGenerateRows="false" ><Fields><asp:TemplateField HeaderText="ID:" HeaderStyle-Font-Bold="true" ItemStyle-VerticalAlign="Top"><ItemTemplate><asp:Label ID="lblTrainingId" runat="server" Text='<%# Bind("tt_id") %>' /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Set Name:" HeaderStyle-Font-Bold="true" ItemStyle-VerticalAlign="Top"><ItemTemplate><asp:Label ID="lblSetName" runat="server" Text='<%# Bind("setName") %>' /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Date:" HeaderStyle-Font-Bold="true" ItemStyle-VerticalAlign="Top"><ItemTemplate><asp:Label ID="lblTDate" runat="server" Text='<%# Bind("t_date", "{0:dd/MM/yy}") %>' /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Surname:" HeaderStyle-Font-Bold="true" ItemStyle-VerticalAlign="Top"><ItemTemplate><asp:Label ID="lblSurname" runat="server" Text='<%# Bind("surname") %>' /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Outcome:" HeaderStyle-Font-Bold="true" ItemStyle-VerticalAlign="Top"><ItemTemplate><%--<asp:Label ID="lblOutcome" runat="server" Text='<%# Bind("o_id") %>'></asp:Label>--%><asp:Image ID="imgStatus" runat="server" ImageUrl='<%# GetImage(CType(Eval("o_id"),Integer)) %>' /></ItemTemplate></asp:TemplateField></Fields></asp:DetailsView><asp:Button ID="btnClose" runat="server" Text="Close" /><br /></div>
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) For Each r As GridViewRow In GridView1.Rows If r.RowType = DataControlRowType.DataRow Then For columnIndex As Integer = 0 To r.Cells.Count - 1 Page.ClientScript.RegisterForEventValidation(r.UniqueID + "$ctl00", columnIndex.ToString()) Next End If Next MyBase.Render(writer) End Sub Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then Dim _singleClickButton As LinkButton = DirectCast(e.Row.Cells(0).Controls(0), LinkButton) Dim _jsSingle As String = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "") ' Add events to each editable cell For columnIndex As Integer = 2 To e.Row.Cells.Count - 1 ' Add the column index as the event argument parameter Dim js As String = _jsSingle.Insert(_jsSingle.Length - 2, columnIndex.ToString()) ' Add this javascript to the onclick Attribute of the cell e.Row.Cells(columnIndex).Attributes("onclick") = js ' Add a cursor style to the cells e.Row.Cells(columnIndex).Attributes("style") += "cursor:pointer;cursor:hand;" Next End If End Sub Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) If e.CommandName.ToString() = "CellClick" Then Dim selectedRowIndex As Integer = Convert.ToInt32(e.CommandArgument.ToString()) Dim selectedColumnIndex As Integer = Convert.ToInt32(Request.Form("__EVENTARGUMENT").ToString()) Dim ServiceNo As String = GridView1.HeaderRow.Cells(selectedColumnIndex).Text.Remove(4) Dim TrainingId As String = GridView1.Rows(selectedRowIndex).Cells(selectedColumnIndex).Text.Remove(0, 1) If TrainingId = "nbsp;" Or TrainingId = String.Empty Then Else ModalPopupExtender1.Show() 'Get the Distinct users in the roles nlAdmin and nlUser Dim strQuery As String = "SELECT string goes here)" Dim cmd As New SqlCommand(strQuery) cmd.Parameters.AddWithValue("@tt_id", TrainingId.ToString) Dim dt As DataTable = GetData(cmd) DetailsView1.DataSource = dt DetailsView1.DataBind() End If End If End Sub