Hi All
i have this page for udpdate :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpdateAssets.aspx.cs" Inherits="Admin_UpdateAssets" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<table cellspacing="1" class="auto-style1">
<tr>
<td class="auto-style2">Asset Name:</td>
<td>
<asp:TextBox ID="txtAssetName" runat="server" Width="248px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">Asset SN:</td>
<td>
<asp:TextBox ID="txtAssetSN" runat="server" Width="248px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">Make:</td>
<td>
<asp:DropDownList ID="ddlMake" runat="server" DataSourceID="dsDDLMake" DataTextField="Make" DataValueField="Make_ID" Height="18px" Width="164px">
</asp:DropDownList>
<asp:SqlDataSource ID="dsDDLMake" runat="server" ConnectionString="<%$ ConnectionStrings:Test_Connection %>" SelectCommand="SP_ddlMake" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="auto-style2">Model:</td>
<td>
<asp:DropDownList ID="ddlModel" runat="server" DataSourceID="dsDDLModel" DataTextField="Model" DataValueField="Model_ID" Height="16px" Width="164px">
</asp:DropDownList>
<asp:SqlDataSource ID="dsDDLModel" runat="server" ConnectionString="<%$ ConnectionStrings:Test_Connection %>" SelectCommand="SP_ddlModel" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="auto-style2">Assigned To:</td>
<td>
<asp:DropDownList ID="ddlEmpList" runat="server" DataSourceID="dsDDLempList" DataTextField="Emp_Name" DataValueField="Emp_ID" Height ="16px" Width="164px">
</asp:DropDownList>
<asp:SqlDataSource ID="dsDDLempList" runat="server" ConnectionString="<%$ ConnectionStrings:Test_Connection %>" SelectCommand="SP_ddlEmpList" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" />
</td>
<td>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="lblmsg" runat="server" Text="Label"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
</td>
</tr>
<tr>
<td class="auto-style2" colspan="2">
<asp:GridView ID="GVAssetList" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="Asset_ID" DataSourceID="dsGVAssetList" GridLines="Vertical" OnSelectedIndexChanged="GVAssetList_SelectedIndexChanged">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Asset_ID" HeaderText="Asset_ID" ReadOnly="True" SortExpression="Asset_ID" />
<asp:BoundField DataField="Asset_Name" HeaderText="Asset_Name" SortExpression="Asset_Name" />
<asp:BoundField DataField="Asset_SN" HeaderText="Asset_SN" SortExpression="Asset_SN" />
<asp:BoundField DataField="Asset_Make" HeaderText="Asset_Make" SortExpression="Asset_Make" />
<asp:BoundField DataField="Asset_Model" HeaderText="Asset_Model" SortExpression="Asset_Model" />
<asp:BoundField DataField="Emp_ID" HeaderText="Emp_ID" SortExpression="Emp_ID" />
<asp:BoundField DataField="Asset_Status" HeaderText="Asset_Status" SortExpression="Asset_Status" />
<asp:BoundField DataField="Make" HeaderText="Make" SortExpression="Make" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
<asp:SqlDataSource ID="dsGVAssetList" runat="server" ConnectionString="<%$ ConnectionStrings:Test_Connection %>" SelectCommand="SP_GetAssetList" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
and the coce behine the page is as below:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Admin_UpdateAssets : System.Web.UI.Page
{
#region Connection
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Test_Connection"].ConnectionString);
#endregion Connection
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GVAssetList_SelectedIndexChanged(object sender, EventArgs e)
{
Session["GvAssetList_ID"] = GVAssetList.SelectedDataKey.Value;
try
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "SP_GetAssetDetails";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Asset_ID", Convert.ToInt32(Session["GvAssetList_ID"]));
con.Open();
SqlDataReader My = cmd.ExecuteReader();
if (My.Read())
{
txtAssetName.Text = My["Asset_Name"].ToString();
txtAssetSN.Text = My["Asset_SN"].ToString();
ddlMake.SelectedValue = My["Asset_Make"].ToString();
ddlModel.SelectedValue = My["Asset_Model"].ToString();
ddlEmpList.SelectedValue = My["Emp_ID"].ToString();
}
con.Close();
}
catch
{
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
Session["GvAssetList_ID"] = GVAssetList.SelectedDataKey.Value;
try
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "SP_EditAsset";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Asset_Name", txtAssetName.Text);
cmd.Parameters.AddWithValue("@Asset_SN", txtAssetSN.Text);
//cmd.Parameters.AddWithValue("@Asset_Make", ddlMake.SelectedValue);
//cmd.Parameters.AddWithValue("@Asset_Model", ddlModel.SelectedValue);
//cmd.Parameters.AddWithValue("@Asset_Status", ddlAssetStatus.SelectedValue);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
con.Close();
lblmsg.Text = "Asset Update!!";
GVAssetList.DataBind();
}
catch
{
}
}
}
and the stored procedure is like below:
USE [TestDB]
GO
/****** Object: StoredProcedure [dbo].[SP_EditAsset] Script Date: 04/12/2016 13:04:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[SP_EditAsset]
@Asset_ID int,
@Asset_Name nvarchar(50),
@Asset_SN nvarchar(50)
--@Asset_Make int,
--@Asset_Model int,
--@Asset_Status nvarchar(50)
AS
BEGIN
--DECLARE @Asset_ID int
--SET @Asset_ID = (select ISNULL(MAX(Asset_ID),0) + 1 from tbl_Asset)
update tbl_Asset set Asset_Name=@Asset_Name, Asset_SN=@Asset_SN
--Asset_Make=@Asset_Make, Asset_Model=Asset_Model,
----@Asset_Status=@Asset_Status
where
Asset_ID=@Asset_ID
END
when i click on update nothing happenes ?!!
could you please tell me why
regards