Please help me sir
Server Error in '/' Application.
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object. Source Error:
Line 97: {
Line 98:
Line 99: GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
Line 100: int Id = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32((sender as Button).CommandArgument)].Values[0]);
Line 101: string Issend_a = "YES";
|
Source File: c:\Users\Administrator\Documents\Visual Studio 2012\Projects\masterpg\masterpg\inbox.aspx.cs Line: 99 Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
masterpg.inbox.Send(Object sender, EventArgs e) in c:\Users\Administrator\Documents\Visual Studio 2012\Projects\masterpg\masterpg\inbox.aspx.cs:99
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +121
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +108
System.Web.UI.WebControls.LinkButton.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) +9764628
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">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="container">
<tr>
<td 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>
<asp:TemplateField HeaderText="Send">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnSend" runat="server" Text="Send" CssClass="btn btn-info"
OnClick="Send"></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="lblId" 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" />
<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#
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 WHERE Issend_a='No'", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
protected void Send(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
int Id = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32((sender as Button).CommandArgument)].Values[0]);
string Issend_a = "YES";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE req SET Issend_a = @Issend_a WHERE Id = @Id"))
{
cmd.Parameters.AddWithValue("@Id", Id);
cmd.Parameters.AddWithValue("@Issend_a", Issend_a);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
row.Visible = false;
}
}
}
}
}