thank you fro reply
the html code is :
<table cellspacing="1" class="auto-style1">
<tr>
<td class="auto-style2">Assets</td>
<td colspan="3"> </td>
</tr>
<tr>
<td class="auto-style2">Asset Name:</td>
<td colspan="3">
<asp:TextBox ID="txtAssetName" runat="server" Width="141px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">SN</td>
<td colspan="3">
<asp:TextBox ID="txtAssetSN" runat="server" Width="141px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">Make:</td>
<td colspan="3" style="margin-left: 40px">
<asp:DropDownList ID="ddlMake" runat="server" Height="18px" Width="151px" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Make" DataValueField="asset_make">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Test_Connection %>" SelectCommand="select DISTINCT asset_make, make from tbl_asset full outer join tbl_make on tbl_Asset.Asset_Make=tbl_Make.Make_ID"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="auto-style2">Model:</td>
<td colspan="3">
<asp:DropDownList ID="ddlModel" runat="server" Height="18px" Width="151px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style2">Asset Status</td>
<td colspan="3">
<asp:DropDownList ID="ddlAssetStatus" runat="server" Height="18px" Width="151px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style2">Assigned to:</td>
<td colspan="3">
<asp:DropDownList ID="ddlEmpList" runat="server" Height="18px" Width="151px" DataSourceID="sda_emplist" DataTextField="Emp_Name" DataValueField="Emp_ID">
</asp:DropDownList>
<asp:SqlDataSource ID="sda_emplist" runat="server" ConnectionString="<%$ ConnectionStrings:Test_Connection %>" SelectCommand="SPa_GetEmpLst" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
<asp:Button ID="btnEdit" runat="server" Text="Edit" OnClick="btnEdit_Click" />
</td>
<td class="auto-style4">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
<td>
<asp:Label ID="lblmsg" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
and the code behine the page is like 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_EditAsset : 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)
{
//if (!Page.IsPostBack)
//{
// ddlMake.DataSource = ASSETNAMEDS;
// ddlMake.DataBind();
//}
}
protected void GRIDASSET_SelectedIndexChanged(object sender, EventArgs e)
{
Session["Grid_ID"] = GRIDASSET.SelectedDataKey.Value;
try
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "SP_GetAssetDetails";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Asset_ID", Convert.ToInt32(Session["Grid_ID"]));
con.Open();
SqlDataReader My = cmd.ExecuteReader();
if (My.Read())
{
txtAssetName.Text = My["Asset_Name"].ToString();
ddlMake.SelectedValue = My["Asset_Make"].ToString();
ddlModel.SelectedValue = My["Asset_Model"].ToString();
ddlAssetStatus.SelectedValue = My["Asset_Status"].ToString();
}
con.Close();
}
catch
{
}
}
protected void ASSETSEARCHTXT_TextChanged(object sender, EventArgs e)
{
string str = ((TextBox)GRIDASSET.HeaderRow.FindControl("ASSETSEARCHTXT")).Text;
GRIDASSETDS.SelectCommandType = SqlDataSourceCommandType.Text;
GRIDASSETDS.SelectCommand = "select Asset_ID,Asset_Name, Asset_SN, Asset_Make,Asset_Model, Emp_ID, Asset_Status from tbl_Asset where asset_name like '%" + str + "%'";
GRIDASSET.DataBind();
((TextBox)GRIDASSET.HeaderRow.FindControl("ASSETSEARCHTXT")).Text = str;
GRIDASSET.SelectedIndex = -1;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string str = ((DropDownList)GRIDASSET.HeaderRow.FindControl("ddlMakeGV")).SelectedValue;
GRIDASSETDS.SelectCommandType = SqlDataSourceCommandType.Text;
GRIDASSETDS.SelectCommand = "select Asset_ID,Asset_Name, Asset_SN, Asset_Make,Asset_Model, Emp_ID, Asset_Status, Make from tbl_Asset inner join tbl_Make on tbl_Asset.Asset_Make=tbl_Make.Make_ID where Asset_Make like '%" + str + "%'";
GRIDASSET.DataBind();
//((DropDownList)GRIDASSET.HeaderRow.FindControl("ddlMake")).SelectedItem.Text = str;
GRIDASSET.SelectedIndex = -1;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void btnEdit_Click(object sender, EventArgs e)
{
//Session["Grid_ID"] = GRIDASSET.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 V = cmd.ExecuteReader();
// con.Close();
// lblmsg.Text = "Asset Update!!";
//}
//catch
//{
//}
}
}
and stored procedure is like below :
/****** Object: StoredProcedure [dbo].[SP_EditAsset] Script Date: 02/12/2016 18:50:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[SP_EditAsset]
@Asset_Name nvarchar(50),
@Asset_SN nvarchar(50),
@Asset_Make int,
@Asset_Model int,
@Emp_ID 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_ID=@Asset_ID, Asset_Name=@Asset_Name, Asset_SN=@Asset_SN, Asset_Make=@Asset_Make, Asset_Model=Asset_Model,Emp_ID=@Emp_ID,
@Asset_Status=@Asset_Status
where
Asset_ID=@Asset_ID
END
regards