Lamloumi Afif
Lamloumi Afif

Reputation: 9081

Add an Ajax function to a gridview within Asp.net application

I have this GridView in my Asp.net application

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True">
        <Columns>
            <asp:TemplateField >
                <ItemTemplate>
                    <asp:Button ID="Savebtn" runat="server" Text="تحديث البيانات"  OnClick="gv_RowEditing"/>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="السعر الأقصى">
                <ItemTemplate>
                    <asp:TextBox ID="maxtxt" runat="server" Text='<%#Eval("prix max")%>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="السعر الأدنى"  >
                <ItemTemplate>
                    <asp:TextBox ID="mintxt" runat="server"  Text='<%#Eval("prix min")%>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Datvente" HeaderText="التاريخ" SortExpression="Datvente" />
            <asp:BoundField DataField="NomAdh" HeaderText="الإسم و اللقب" SortExpression="NomAdh" />
            <asp:BoundField DataField="CodAdh" HeaderText="المنخرط" SortExpression="CodAdh" />

             <asp:TemplateField >
                <ItemTemplate>

                    <asp:HiddenField ID="Ref" runat="server"  Value='<%#Eval("Ref")%>'/>
                </ItemTemplate>
            </asp:TemplateField>


        </Columns>
    </asp:GridView>

Each row contains a submit button to update it.it works but i need to add an ajax function that verify if the row is modified or not . if the case when the user modify the values of a row and forgot to submit the changes the row change its color to red for example.

  1. What is the best idea to do this?
  2. how can i change my code to add this feature?

Upvotes: 0

Views: 1067

Answers (1)

msm2020
msm2020

Reputation: 181

1- Create webservice to Call you server side:

[WebMethod]
public string RowEditing(string firstName, string lastName) // your paramenter
{
     //       your code here 
     return "";
}

2- add javascipt function :

function grEdit(){
   // do some script here 
   $.ajax({
      type: "POST",
      url: "MyWebService.asmx/RowEditing",
      data: "firstName=Aidy&lastName=F", // the data and parameter
      dataType: "text",
      success: function (data) {
       // action when succ
      }
   });
 }

3- call inside grid :

< asp:Button ID="Savebtn" runat="server" Text="تحديث البيانات" OnClick="grEdit(); return false;"/>

Upvotes: 1

Related Questions