0
please help me.. how should i cancel the editing, and update and delete the row from gridview. by using store procedure. and binding the table column with <asp:BoundField></asp:BoundField>..


here is my Html code.

<asp:GridView ID="gridviwtbl"  runat="server" AllowPaging="true" ShowFooter="true" 
            PageSize="10" OnPageIndexChanging="GridViewSample_PageIndexChanging" 
            OnRowDeleting="GridViewSample_RowDeleting" 
            OnRowEditing="GridViewSample_RowEditing"  AutoGenerateColumns="false" 
            OnRowUpdating="Gridviw_RowUpdating" AutoGenerateEditButton="false" AutoGenerateDeleteButton="false" Width="140px" 
            onselectedindexchanged="gridviwtbl_SelectedIndexChanged" 
            onrowcancelingedit="gridviwtbl_RowCancelingEdit" 
            onrowcommand="gridviwtbl_RowCommand">

        <Columns>
            <asp:TemplateField>
                <HeaderTemplate>
                    <input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server" type="checkbox" />
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="chkApplianceSelector" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Edit" ShowHeader="true">
                <EditItemTemplate>
                    <asp:LinkButton runat="server" CommandName="Update">Update</asp:LinkButton>
                    <asp:LinkButton ID="LinkButton1"  runat="server">Cancel</asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton runat="server" CommandName="edit">Edit</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Delete" ShowHeader="true">
                <ItemTemplate>         
                    <asp:LinkButton runat="server" OnClientClick="return confirm('You really want to delete selected item ?');"
                           CommandName="Delete">Delete</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>

                <asp:BoundField  DataField="firstName" HeaderText="first Name" ReadOnly="true" />
                <asp:BoundField DataField="Lastname" HeaderText="LastName" ReadOnly="true" /> 
                <asp:BoundField DataField="EmailId" HeaderText="EmailId" ReadOnly="true" />
                <asp:BoundField DataField="Pasword" HeaderText="Pasword" ReadOnly="false" />
                <asp:BoundField DataField="ConformPasword" HeaderText="ConfromPassword" ReadOnly="false" />
                <asp:BoundField DataField="PhoneNO" HeaderText="Phone NO" ReadOnly="False" />
                <asp:BoundField DataField="PermanentAddress" HeaderText="Address" ReadOnly="False" />
                <asp:BoundField DataField="Gender" HeaderText="Gender" ReadOnly="true" />
                <asp:BoundField DataField="Qualification" HeaderText="Qualification" ReadOnly="False" />
                <asp:BoundField DataField="dateOfBirth" HeaderText="Birth Date" ReadOnly="true" />
                <asp:BoundField DataField="CityName" HeaderText="City Name" ReadOnly="False" />
                <asp:BoundField DataField="Questions" HeaderText="Questions" ReadOnly="true" />
                <asp:BoundField DataField="Answers" HeaderText="Answers" ReadOnly="true" />
</Columns>
</asp:GridView>


here is my .cs code for rowdeleting/////

 protected void GridViewSample_RowDeleting(object sender, GridViewDeleteEventArgs e)

        {

            string EmailId = ((TextBox)gridviwtbl.Rows[e.RowIndex].Cells[0].Controls[0]).Text;

            SqlConnection connection = new SqlConnection(connectionstring);
          if(e.RowIndex>-1)
            {


                connection.Open();
                SqlCommand command = new SqlCommand();
              command.Parameters.AddWithValue("@Email",gridviwtbl.DataKeys[e.RowIndex].Value.ToString());
                command.Connection = connection;
                command.CommandText = "demoDelete";
                command.CommandType = CommandType.StoredProcedure;
                //SqlDataAdapter adapter = new SqlDataAdapter(command);

                command.ExecuteNonQuery();

            }




          connection.Close();         
            this.bindData();

            ScriptManager.RegisterClientScriptBlock(this, GetType(), "message", "alert('data deleted successfully')", true);

        }

and for updating....

 protected void Gridviw_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
         //int gridd=int.Parse(gridviwtbl.DataKeys[e.RowIndex].Value.ToString());
         //string clmindx = ((TextBox)gridviwtbl.Rows[e.RowIndex].Cells[0].Controls[0]).Text;
         SqlConnection connection = new SqlConnection(connectionstring);
         connection.Open();
         SqlCommand command = new SqlCommand();
         command.Connection = connection;
         command.CommandText = "demoUpdate";
         command.CommandType = CommandType.StoredProcedure;
         command.ExecuteNonQuery();
         connection.Close();
         gridviwtbl.EditIndex = -1;
         DataBind();

        }


        and for editcancel...


         protected void gridviwtbl_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gridviwtbl.EditIndex = -1;
            bindData();
        }


        .but among des nothing is working properly... please help// thank you in adavnce..
2
Contributors
1
Reply
14
Views
3 Years
Discussion Span
Last Post by YA RAMSAMKER
0

There is another way

wereby everything is auto generated the add,update and delete
and not much coding is required

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.