Antarr Byrd
Antarr Byrd

Reputation: 26189

Gridview Not Triggering Events

I'm trying to use the events on my Gridview control. But its not firing the events when expected. i.e, for OnSelectedIndexChanged, when changing the selected cell/row nothing happens. I've tried with OnSelectedIndexChanged as well as OnRowUpdating. The breakpoint is never hit in gvQ15_RowUpdating. I've even tried using the OnTextChanged event for the child textboxes or the gridview and they are not firing.

Markup

<asp:GridView AutoPostBack="true" ID="gvQ15" runat="server" AllowPaging="false" AutoGenerateColumns="false" >
    <Columns>
        <asp:TemplateField HeaderText="Prescription Medication Name" ItemStyle-Width="25%">
            <ItemTemplate>
                <asp:TextBox ID="txtPrescriptionMedicationName" runat="server" Width="100%" OnTextChanged="txtPrescriptionMedicationName_TextChanged" BordewWidth="0" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Date Originally Prescribed" ItemStyle-Width="10%">
            <ItemTemplate>
                <asp:TextBox ID="txtDateOriginallyPrescribed" runat="server" Style="min-width: 110px; width: 100%;" BorderWidth="0" OnTextChanged="txtDateOriginallyPrescribed_TextChanged" />
                <asp:MaskedEditExtender ID="meetxtDateOriginallyPrescribed" runat="server" MaskType="date" UserDateFormat="MonthDayYear" Mask="99/99/9999" TargetControlID="txtDateOriginallyPrescribed" ClearMaskOnLostFocus="true"  />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Frequency and Dosage" ItemStyle-Width="25%">
            <ItemTemplate>
                <asp:TextBox ID="txtFrequencyAndDosage" runat="server" Width="100%" BorderWidth="0" OnTextChanged="txtFrequencyAndDosage_TextChanged" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Condition" ItemStyle-Width="25%">
            <ItemTemplate>
                <asp:TextBox ID="txtCondition" runat="server" Width="100%" BorderWidth="0" OnTextChanged="txtCondition_TextChanged" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Onset Date" ItemStyle-Width="10%">
            <ItemTemplate>
                <asp:TextBox ID="txtConditionOnsetDate" runat="server" style="min-width:110px;width:100%" BorderWidth="0" OnTextChanged="txtConditionOnsetDate_TextChanged" />
                <asp:MaskedEditExtender ID="meeConditionOnsetDate" runat="server" MaskType="date" UserDateFormat="MonthDayYear" Mask="99/99/9999" TargetControlID="txtConditionOnsetDate" ClearMaskOnLostFocus="true" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Code Behind

 Protected Sub gvQ15_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
    Session("Prescriptions") = gvQ15.DataSource
 End Sub

Upvotes: 0

Views: 299

Answers (1)

user1773603
user1773603

Reputation:

Add the CausesValidation="False" attribute to your CommandField.

<asp:commandfield ShowEditButton="True" CausesValidation="False" HeaderText="Edit"/>

Or,

Add the EnableViewState="True" attribute to your GridView.


For TemplateField use this:

<asp:TemplateField HeaderText="Command">
    <ItemTemplate>
        <asp:Button CommandName="Edit"   Text="Edit"   ID="btnEdit" Runat="server"></asp:Button>
        <asp:Button CommandName="Delete" Text="Delete" ID="btnDel"  Runat="server"></asp:Button>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:Button CommandName="Update" Text="Update" ID="btnUpdate"  Runat="server"></asp:Button>
        <asp:Button CommandName="Cancel" Text="Delete" ID="btnCancel"  Runat="server"></asp:Button>
    </EditItemTemplate>
</asp:TemplateField>

Upvotes: 1

Related Questions