Dear Sir,
While i have insert values in table , i have getting mention error.
Server Error in '/' Application.
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 74: {
Line 75: GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
Line 76: int Id = Convert.ToInt32("Id.Text");
Line 77: // int Id = " + Id.Text +";
Line 78: string asset_status = "ddlTest.Text";
|
Source File: c:\Users\Administrator\Documents\Visual Studio 2012\Projects\masterpg\masterpg\inbox.aspx.cs Line: 76
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +12516991
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +122
System.Convert.ToInt32(String value) +48
masterpg.inbox.btnSave_Click(Object sender, EventArgs e) in c:\Users\Administrator\Documents\Visual Studio 2012\Projects\masterpg\masterpg\inbox.aspx.cs:76
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9847682
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +211
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1696
|
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.9206.0
HTML
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true"
CodeFile="inbox.aspx.cs" Inherits="masterpg.inbox" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.auto-style2 { width: 1148px; }
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="container" style="width: 1620px; height: 691px; margin-left: 300px;">
<tr>
<td style="font-size: xx-small; background-color: #003366;" class="auto-style2">
<asp:GridView ID="GridView1" runat="server" CssClass="table table-striped table-hover"
DataKeyNames="Id" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="1580px">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="Id" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Employee Id">
<ItemTemplate>
<asp:Label ID="EmpCode" runat="server" Text='<%# Eval("EmpCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Asset Name">
<ItemTemplate>
<asp:Label ID="asst_typ" runat="server" Text='<%# Eval("asst_typ") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location">
<ItemTemplate>
<asp:Label ID="lcn" runat="server" Text='<%# Eval("lcn") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Purpose">
<ItemTemplate>
<asp:Label ID="prps" runat="server" Text='<%# Eval("prps") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remark">
<ItemTemplate>
<asp:Label ID="rmk" runat="server" Text='<%# Eval("rmk") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEdit" runat="server" Text="View" CssClass="btn btn-info"
OnClick="Display"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</td>
</tr>
</div>
<div>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×</button>
<h4 class="modal-title">
Requst Details</h4>
</div>
<div class="modal-body">
<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
<div class="form-group">
<font size='2'>
<b>ID :</b> <asp:Label ID="Id" runat="server" Text="Id"></asp:Label> <br /><br />
<b>Employee Id : </b><asp:Label ID="EmpCode" runat="server" Text="EmpCode"></asp:Label>
</font>
</div>
<font size='2'>
<div class="form-group">
<b>Asset Type : </b> <asp:Label ID="asst_typ" runat="server" Text=""></asp:Label>
</font>
</div>
<font size='2'>
<div class="form-group">
<b>Location : </b><asp:Label ID="lcn" runat="server" Text="lcn"></asp:Label> ,
<b>Purpose : </b><asp:Label ID="prps" runat="server" Text="prps"></asp:Label><br /><br />
<b>Remark : </b><asp:Label ID="rmk" runat="server" Text="rmk"></asp:Label>
</div>
</font>
</div>
<font size='2'>
<div class="form-group">
<b>Asset Status : <asp:dropdownlist id="ddlTest" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList_Changed" >
<asp:ListItem Text="--Select --" Value="C" />
<asp:ListItem Text="Available" Value="Available" />
<asp:ListItem Text="Not_Available" Value="Not_Available" />
</asp:dropdownlist>
<b> <asp:Label ID="Label1" runat="server" Text="Intalation date :"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Text="dd/mm/yyyy"></asp:TextBox>
</b><br /><br />
<b> <asp:Label ID="Label2" runat="server" Text="Asset Serial No.:"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></b>
<br /><br />
<b> <asp:Label ID="Label3" runat="server" Text="Remark :"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" width="300px"></asp:TextBox> </b>
</div>
</font>
</div>
<div class="modal-footer">
<asp:Button ID="btnchk" runat="server" Text="Check" OnClick="btnchk_Click" ToolTip='Click here to Check Asset Details'
CssClass="btn btn-info" />
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" ToolTip='Click here to Save Data'
CssClass="btn btn-info" />
<asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click" ToolTip='Click here to Send Data'
CssClass="btn btn-info" />
<button type="button" class="btn btn-info" data-dismiss="modal">
Close</button>
</div>
</div>
</div>
<script type='text/javascript'>
function openModal() {
$('[id*=myModal]').modal('show');
}
</script>
</div>
</asp:Content>
Code
C#
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;
namespace masterpg
{
public partial class inbox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM req ", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
protected void Display(object sender, EventArgs e)
{
int rowIndex = Convert.ToInt32(((sender as LinkButton).NamingContainer as GridViewRow).RowIndex);
GridViewRow row = GridView1.Rows[rowIndex];
Id.Text = (row.FindControl("Id") as Label).Text;
EmpCode.Text = (row.FindControl("EmpCode") as Label).Text; ;
asst_typ.Text = (row.FindControl("asst_typ") as Label).Text;
lcn.Text = (row.FindControl("lcn") as Label).Text;
prps.Text = (row.FindControl("prps") as Label).Text;
rmk.Text = (row.FindControl("rmk") as Label).Text;
ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openModal();", true);
}
protected void btnchk_Click(object sender, EventArgs e)
{
if (asst_typ.Text == "Desktop_PC")
{
Response.Redirect("desktop_pc1.aspx?Id=" + Label3.Text);
}
if (asst_typ.Text == "All_in_One_PC")
{
// Response.Redirect("pending.aspx?Id=" + row.Cells[0].Text + "&EmplooyeId=" + Label1.Text + "&emp_nm=" + Label2.Text + "&dept=" + Label3.Text);
Response.Redirect("aio1.aspx?Id=" + Label3.Text);
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
int Id = Convert.ToInt32("Id.Text");
// int Id = " + Id.Text +";
string asset_status = "ddlTest.Text";
string intalation_dt = "TextBox2.Text";
string asset_serial_no = "TextBox3.Text";
string Remark_a = "TextBox1.Text";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE req SET asset_status = @asset_status, intalation_dt=@intalation_dt,asset_serial_no=@asset_serial_no,Remark_a=@Remark_a WHERE Id =@Id"))
{
cmd.Parameters.AddWithValue("@Id", Id);
cmd.Parameters.AddWithValue("@asset_status", asset_status);
cmd.Parameters.AddWithValue("@intalation_dt", intalation_dt);
cmd.Parameters.AddWithValue("@asset_serial_no", asset_serial_no);
cmd.Parameters.AddWithValue("@Remark_a", Remark_a);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
row.Visible = false;
}
}
}
protected void btnSend_Click(object sender, EventArgs e)
{
//Your Send code.
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
protected void DropDownList_Changed(object sender, EventArgs e)
{
if (ddlTest.SelectedItem.Value == "Available")
{
TextBox1.Visible = true;
TextBox2.Visible = true;
TextBox3.Visible = true;
Label1.Visible = true;
Label2.Visible = true;
Label3.Visible = true;
}
if (ddlTest.SelectedItem.Value == "Not_Available")
{
TextBox1.Visible = false;
TextBox2.Visible = false;
TextBox3.Visible = false;
Label1.Visible = false;
Label2.Visible = false;
Label3.Visible = false;
}
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "openModal();", true);
}
}
}