3 Replies - 885 Views - Last Post: 17 February 2015 - 06:58 AM

#1 Rajking1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-February 15

not firing the update/cancel button

Posted 17 February 2015 - 02:46 AM

this is my aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Both" onselectedIndexChanged="DataList1_SelectedIndexChanged" Width="943px" >
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
  <HeaderTemplate>
                   Empid       Ename   Designation Doj     Salary      DeptNo       Edit/Update
            </HeaderTemplate>
            <ItemStyle ForeColor="#000066" />
            <ItemTemplate>
               <%#Eval ("EmpId") %>
                <%#Eval("Ename") %>
                <%#Eval("Designation") %>
                <%#Eval("Doj") %>
                <%#Eval("Salary") %>
                <%#Eval("DeptNO") %>
                    <asp:Button ID="btnEdit" Text="Edit" runat ="server" CommandName="Edit" />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Label ID="lblEmpId" Text='<%#Eval ("empId") %>' runat="server" />

 <asp:TextBox ID="TextBox1" Text='<%#Bind ("ename") %>' runat="server" />
    <asp:TextBox ID="txtEsal" Text='<%#Bind ("salary") %>' runat="server" />
<asp:TextBox ID="txtDesignation" runat="server" Width ="60" Text='<%#Bind ("Designation") %>'/>
                <asp:TextBox ID="txtDoj" runat="server" Width="60" Text='<%#Bind ("Doj") %>' />
                <asp:TextBox ID="txtDeptNo" runat="server" Width="20" Text='<%#Bind ("DeptNo") %>' />
                <asp:Button ID="BtnUpdate" Text="Update" CommandName="cmdUpdate" runat="server" /> 
<asp:Button ID="btnCancel" Text="Cancel" CommandName="cmdCancel" runat="server" />          
            </EditItemTemplate>
        </asp:DataList>
    </form>
</body>
</html>

This post has been edited by Atli: 17 February 2015 - 03:11 AM
Reason for edit:: Use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: not firing the update/cancel button

#2 djjeavons  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 114
  • View blog
  • Posts: 417
  • Joined: 09-January 09

Re: not firing the update/cancel button

Posted 17 February 2015 - 04:25 AM

Hi

You need to add the OnCommand attribute to your buttons and tie these up to an event in your code behind. For example:

<asp:Button ID="btnEdit" Text="Edit" runat ="server" CommandName="Edit" OnCommand="btnEdit_Command" />



    Protected Sub btnEdit_Command(sender As Object, e As CommandEventArgs)

    End Sub




HTH
Was This Post Helpful? 0
  • +
  • -

#3 Rajking1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-February 15

Re: not firing the update/cancel button

Posted 17 February 2015 - 05:03 AM

you mean
protected void btnEdit_Command(sender As............)
like this

my .cs code is

public partial class _Default : System.Web.UI.Page
{
    SqlConnection Con = new SqlConnection("server=(local);user id=sa;password=sa123;database=empdetails;");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            GetData();
    }
    private void GetData()
    {
        string s = "select * from empdetails";
        SqlDataAdapter Da = new SqlDataAdapter(s, Con);
        DataSet Ds = new DataSet();
        Da.Fill(Ds, "Empdetails");
        DataList1.DataSource = Ds.Tables[0];
        DataList1.DataBind();
    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            DataList1.EditItemIndex = e.Item.ItemIndex;
            GetData();
        }
        else if (e.CommandName == "cmdCancel")
        {
            DataList1.EditItemIndex = -1;
            GetData();
        }
        else if (e.CommandName == "Update")
        {
            Label L1 = (Label)e.Item.FindControl("lblEmpId") as Label;
            int newEmpId=Convert.ToInt32(L1.Text);
            TextBox T1 = (TextBox)e.Item.FindControl("txtEname");
            string NewEname = T1.Text;
            TextBox T2 = (TextBox)e.Item.FindControl("txtDesignation");
            string NewDesignation = T1.Text;
            TextBox T3 = (TextBox)e.Item.FindControl("txtDoj");
            DateTime Doj=Convert.ToDateTime(T1.Text);
            TextBox T4 = (TextBox)e.Item.FindControl("txtSalary");
            double salary = Convert.ToDouble(T1.Text);
            TextBox T5 = (TextBox)e.Item.FindControl("txtDeptNo");
            int DeptNo = Convert.ToInt32(T1.Text);
            //       Label L1 = (Label)e.Item.FindControl("lblEmpId");

            string s = "update Empdetails set [email protected],[email protected],[email protected],[email protected],[email protected] where [email protected]";
            SqlCommand cmd = new SqlCommand(s, Con);
            cmd.Parameters.AddWithValue("@p1", T1.Text);
            cmd.Parameters.AddWithValue("@p2", T2.Text);
            cmd.Parameters.AddWithValue("@p3", T3.Text);
            cmd.Parameters.AddWithValue("@p4", T4.Text);
            cmd.Parameters.AddWithValue("@P5", T5.Text);
            cmd.Parameters.AddWithValue("@p6", L1.Text);
            Con.Open();
            cmd.ExecuteNonQuery();
            Con.Close();
            DataList1.EditItemIndex = -1;
            GetData();
        }
    }

This post has been edited by tlhIn`toq: 17 February 2015 - 05:52 AM
Reason for edit:: Please use code tags as shown everywhere including the box where you typed your question

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5828
  • View blog
  • Posts: 19,868
  • Joined: 05-May 12

Re: not firing the update/cancel button

Posted 17 February 2015 - 06:58 AM

Moving to ASP.NET...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1