locked
problem on gridview rowdata bound section RRS feed

  • Question

  • User-148701852 posted

    Hello,

    i am trying to use edit template at any particular row of grid view but it always show me null reference error. 

    In this particular page i use a grid view to show the respective data and allow user to insert file and respective data to the field if it is blank and if there a contain already present then user can use it to get permission by requesting higher authority permission to edit on the existing data.  i use 2 link button and try to hide button respectively as the column Reference doc empty or fill the button will show accordingly.  It work fine if there any record present in that column but if any of data will blank and i go for edit the 2nd row instead of first row it always throws me an error. can you help me on that. I am sending you the codes and alsp cursors i used in backend stored procedures

    // front end

    <%@ Page Title="" Language="C#" MasterPageFile="~/OCPL_MAST.Master" AutoEventWireup="true" CodeBehind="New_LA_Case.aspx.cs" Inherits="OCPL.Application.New_LA_Case" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="Head_Content" runat="server">
    <link rel="shortcut icon" type="image/x-icon" href="../../img/favocpl.jpg" />
    <script type="text/javascript">

    //this will help to open the monitor LA-Case Status tab
    function openUpadteTab() {
    $("#insert").removeClass("active");
    $("#insertli").removeClass("active");
    $("#insertli").removeClass("in");
    $('#insertli').removeAttr('data-toggle');
    $('#updateli').removeAttr('data-toggle');
    $("#insertli").addClass("disabled");
    $("#updateli").addClass("active");
    $("#update").addClass("active");
    $("#update").addClass("in");
    }
    function opendefultTab() {
    $("#insert").addClass("active");
    $("#insertli").addClass("active");
    $("#insertli").addClass("in");
    $("#updateli").addClass("disabled");
    $("#updateli").removeClass("active");
    $('#insertli').removeAttr('data-toggle');
    $('#updateli').removeAttr('data-toggle');
    $("#update").removeClass("active");
    $("#update").removeClass("in");
    }
    </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="Body_Content" runat="server">
    <script type="text/javascript">
    function ShowInsuranceDoc() {
    var aadhar = document.getElementById('<%=hdnPrintdoc.ClientID %>').value;
    aadhar = aadhar.replace(/\\/g, "/");
    var res = aadhar.split("Document/");
    window.open("../../Application/Document/" + res + "", "_new", "resizeable,scrollbar");
    }
    </script>
    <script>
    function pdf(url) {
    window.open(url, '_blank');
    }
    //function view() {
    // window.open('ViewDetails.aspx', '_blank');
    //}
    </script>
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
    <style>
    .pannel {
    height: 25px;
    width: 100%;
    background-color: cadetblue;
    opacity: 1.05;
    text-align: center;
    color: white;
    }
    </style>
    <div class="header">
    <h1 class="page-title">Manage LA Case </h1>
    <ol class="breadcrumb">
    <li><a href="../DashBoard_info/DM_Dashboard.aspx">Home</a></li>
    <li class="active">Land Management </li>
    </ol>
    <div class="clearfix"></div>
    </div>
    <div id="page-inner">
    <div class="row">
    <ul class="nav nav-tabs">
    <li class="active" id="insertli"><a href="#insert">Insert a New LA Case</a></li>
    <li id="updateli"><a href="#update">Managae LA Case Status</a></li>
    </ul>

    <div class="tab-content">
    <div id="insert" class="tab-pane fade in active ">
    <div class="col-lg-12">
    <div class="panel panel-default">
    <asp:LinkButton ID="back" runat="server" class="btn-back" OnClick="back_Click">Back</asp:LinkButton>
    <%--<a href="../Land_Management/LA_Case_Abstract.aspx" class="btn-back">Back </a>--%>
    <div class="col-md-4 col-md-offset-4 box" style="margin-top: 20px;">
    <asp:Panel ID="panelinputnew" runat="server">
    <h3 class="box-title" id="exampleModalLabel">Insert a New Acquisition</h3>
    <div class="box-body">
    <div class="form-group col-md-12">
    <asp:Label ID="lblvillagename" runat="server" Text="Village Name:"></asp:Label>
    <asp:DropDownList ID="ddlvillagename" CssClass="form-control" runat="server"></asp:DropDownList>
    </div>
    <div class="form-group col-md-12">
    <asp:Label ID="lbllac" runat="server" Text="LA-Case:"></asp:Label>
    <asp:TextBox ID="txtlacno" CssClass="form-control" runat="server"></asp:TextBox>
    </div>
    <div class="form-group col-md-12">
    <asp:Label ID="lbllandclasstype" runat="server" Text="Land Class:"></asp:Label>
    <asp:DropDownList ID="ddllandclass" CssClass="form-control" AutoPostBack="true" runat="server">
    <asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
    <asp:ListItem Value="1" Text="Govt."></asp:ListItem>
    <asp:ListItem Value="2" Text="Private"></asp:ListItem>
    <asp:ListItem Value="3" Text="Forest"></asp:ListItem>
    </asp:DropDownList>
    </div>
    <div class="form-group col-md-12">
    <asp:Label ID="lbldt" runat="server" Text="Date:"></asp:Label>
    <asp:TextBox ID="txtdt" runat="server" TextMode="Date" CssClass="form-control"></asp:TextBox>
    </div>
    <div class="form-group col-md-12">
    <asp:Label ID="lblareainacre" runat="server" Text="Area(in Acres):"></asp:Label>
    <asp:TextBox ID="txtareainacre" runat="server" CssClass="form-control"></asp:TextBox>
    </div>
    <div class="form-group col-md-12">
    <asp:Label ID="lblremark" runat="server" Text="Land Transfer Type:"></asp:Label>
    <asp:TextBox ID="txtremark" CssClass="form-control" runat="server"></asp:TextBox>
    </div>
    <div class="form-group col-md-12">
    <asp:Button ID="btnsave" runat="server" Text="Save" OnClick="btnsave_Click" CssClass="btn btn-info" />
    <asp:Button ID="btncancel" runat="server" Text="Cancel" OnClick="btncancel_Click" CssClass="btn btn-danger" />
    </div>
    </div>

    </asp:Panel>
    </div>
    <div class="clearfix"></div>
    </div>
    <div class="clearfix"></div>
    </div>
    </div>
    <%-- col-md-offset-4 box --%>
    <div id="update" class="tab-pane fade">
    <div class="col-lg-12">
    <div class="panel panel-default">
    <asp:LinkButton ID="back2" runat="server" class="btn-back" OnClick="back_Click">Back</asp:LinkButton>
    <div class="col-md-12 " style="margin-top: 20px;">
    <asp:Panel ID="pnlupdatests" runat="server">
    <h3 class="box-title" id="exampleModalLabel1" style="margin-top: 10px;">Manage LA Case Status</h3>
    <div class="box-body">
    <div class="form-group col-md-4">
    <asp:Label ID="lbllandclass" runat="server" Text="Land Type:"></asp:Label>
    <asp:TextBox ID="txtlandclassupdt" Enabled="false" runat="server" CssClass="form-control"></asp:TextBox>
    </div>
    <div class="form-group col-md-4">
    <asp:Label ID="lblLacnoupdt" runat="server" Text="LAC No:"></asp:Label>
    <asp:TextBox ID="txtlacupdt" Enabled="false" CssClass="form-control" runat="server"></asp:TextBox>
    </div>
    <div class="form-group col-md-12">
    <asp:GridView ID="grdLacaseinput" OnRowDataBound="grdLacaseinput_RowDataBound" OnRowEditing="grdLacaseinput_RowEditing" OnRowCancelingEdit="grdLacaseinput_RowCancelingEdit" OnRowUpdating="grdLacaseinput_RowUpdating" OnRowCommand="grdLacaseinput_RowCommand" CssClass="table table-bordered table-striped" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:TemplateField HeaderText="SL NO:">
    <ItemTemplate>
    <%#Container.DataItemIndex+1%>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Notifications:">
    <ItemTemplate>
    <asp:Label ID="lblnotice" runat="server" Text='<%#Eval("NOTICE_TEMP") %>'></asp:Label>
    <asp:Label ID="lbllamscode" Visible="false" runat="server" Text='<%#Eval("LAMS_CODE") %>'></asp:Label>
    <asp:Label ID="lbllamsseq" Visible="false" runat="server" Text='<%#Eval("LAMS_SEQ") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtnotice" runat="server" Enabled="false" Text='<%#Eval("NOTICE_TEMP") %>' CssClass="form-control"></asp:TextBox>
    <asp:TextBox ID="txtlamscode" Visible="false" runat="server" Text='<%#Eval("LAMS_CODE") %>' CssClass="form-control"></asp:TextBox>
    <asp:TextBox ID="txtlamsseq" Visible="false" runat="server" Text='<%#Eval("LAMS_SEQ") %>' CssClass="form-control"></asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Date">
    <ItemTemplate>
    <asp:Label ID="lblmadate" runat="server" Text='<%#Eval("MA_DATE") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtmadate" runat="server" TextMode="Date" Text='<%#Eval("MA_DATE") %>' CssClass="form-control"></asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Remark">
    <ItemTemplate>
    <asp:Label ID="lblremark" runat="server" Text='<%#Eval("REMARK") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtremark" runat="server" Text='<%#Eval("REMARK") %>' CssClass="form-control"></asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Reference">
    <ItemTemplate>
    <asp:LinkButton ID="lnkrefdoc" CommandName="viewdocmnt" runat="server" Text='<%#Eval("REF_DOC") %>' ToolTip="View Documnet"></asp:LinkButton>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:FileUpload ID="flupld" CssClass="form-control" runat="server" />
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:LinkButton ID="lnkbtnupdate" CommandName="Edit" runat="server"><i class="fa fa-edit"></i></asp:LinkButton>
    <asp:LinkButton ID="lnkbtnreqst" CommandName="request" runat="server">REQUEST TO CHANGE</i></asp:LinkButton>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:Button ID="btnconfirm" CssClass="btn btn-success" CommandName="Update" Text="Confirm" runat="server"></asp:Button>
    <asp:Button ID="btncancel" CssClass="btn btn-danger" CommandName="Cancel" Text="Cancel" runat="server"></asp:Button>
    </EditItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    <asp:HiddenField ID="hdnPrintdoc" runat="server" />
    </div>
    </div>
    </asp:Panel>
    </div>
    <div class="clearfix"></div>
    </div>
    <div class="clearfix"></div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </asp:Content>

    //back end

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;
    using DTO;
    using BAL;
    using UtilityClass;
    using System.Data.SqlTypes;
    using System.IO;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using iTextSharp.text.html;
    using iTextSharp.text.html.simpleparser;

    namespace OCPL.Application
    {
    public partial class New_LA_Case : System.Web.UI.Page
    {
    CommonBAL objbal = new CommonBAL();
    private DataTable dt;
    private List<CommonDTO> objlist;
    private CommonDTO paramobj;
    string lacno = "";
    string laccode = "";
    string landclass = "";
    string lams_code = "";
    string lams_seq = "";
    string csts="";
    string pervsts = "";
    string notification = "";
    string uplamscode = "";
    string uplamsseq = "";
    string upmadate = "";
    string upremark = "";
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    populatevalue();
    if (laccode == "")
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "opendefultTab();", true);
    Bindvillage();
    }
    else
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "openUpadteTab();", true);
    populateform();
    }
    }
    }
    private void populatevalue()
    {
    lacno = Session["lacasecarry"].ToString();
    if (lacno != "")
    {
    DataTable dt1 = new DataTable();
    dt1 = CommonClass.ViewDataWithOutConditon("select LACNO_CD,LAND_CLASS,CURR_STS,LAMS_CODE from NEW_LA_CASE_MASTER where LAC_NO='" + lacno + "'");
    laccode = dt1.Rows[0]["LACNO_CD"].ToString();
    landclass = dt1.Rows[0]["LAND_CLASS"].ToString();
    lams_code = dt1.Rows[0]["LAMS_CODE"].ToString();
    csts = dt1.Rows[0]["CURR_STS"].ToString();
    pervsts = csts;
    if (lams_code != "")
    {
    dt = CommonClass.ViewDataWithOutConditon("select LAMS_SEQ from MILESTONE_MASTER where LAMS_CODE='" + lams_code + "'");
    lams_seq = dt.Rows[0]["LAMS_SEQ"].ToString();
    }
    else
    {
    lams_seq = "";
    }
    }
    else
    {
    laccode = "";
    }
    }
    private void populateform()
    {
    txtlacupdt.Text = lacno;
    txtlandclassupdt.Text = landclass;

    dt = new DataTable();
    objlist = new List<CommonDTO>();
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAND_CATG";
    paramobj.PARAMVALUE = landclass;
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAC_CODE";
    paramobj.PARAMVALUE = laccode;
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    dt = CommonClass.ViewData("PROC_NOTICE_ABSTRACT", objlist);
    if (dt.Rows.Count > 0)
    {
    grdLacaseinput.DataSource = dt;
    grdLacaseinput.DataBind();
    }
    else
    {
    grdLacaseinput.DataSource = null;
    grdLacaseinput.DataBind();
    grdLacaseinput.EmptyDataText = "Data not found";
    }
    }
    private void Bindvillage()
    {
    dt = CommonClass.ViewDataWithOutConditon("Select VILL_NAME,VILL_CODE from VILLAGE_CODE_MASTER");
    if (dt.Rows.Count > 0)
    {
    ddlvillagename.DataSource = dt;
    ddlvillagename.DataTextField = "VILL_NAME";
    ddlvillagename.DataValueField = "VILL_CODE";
    ddlvillagename.DataBind();
    ddlvillagename.Items.Insert(0,"--Select--");
    }
    }
    protected void back_Click(object sender, EventArgs e)
    {
    Response.Redirect("Acquisition_Annihiliation.aspx");
    }
    protected void btnsave_Click(object sender, EventArgs e)
    {
    dt = new DataTable();
    objlist = new List<CommonDTO>();
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@VILL_NAME";
    paramobj.PARAMVALUE = ddlvillagename.SelectedItem.ToString();
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@VILL_CODE ";
    paramobj.PARAMVALUE = ddlvillagename.SelectedValue.ToString();
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAC_NO ";
    paramobj.PARAMVALUE = txtlacno.Text;
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LACNO_CD ";
    paramobj.PARAMVALUE = ddlvillagename.SelectedValue+"-"+ txtlacno.Text;
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAC_DT ";
    paramobj.PARAMVALUE = txtdt.Text;
    paramobj.PARAMTYPE = 3;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAND_CLASS ";
    paramobj.PARAMVALUE = ddllandclass.SelectedItem.ToString();
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@AREA_AC ";
    paramobj.PARAMVALUE = txtareainacre.Text;
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    DataTable dt2 = new DataTable();
    dt2 = CommonClass.ViewDataWithOutConditon("select top 1 LAMS_CODE,LA_MS from MILESTONE_MASTER where LAND_CATG='"+ ddllandclass.SelectedItem.ToString() + "'");
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@CURR_STS ";
    paramobj.PARAMVALUE = dt2.Rows[0]["LA_MS"].ToString();
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAMS_CODE ";
    paramobj.PARAMVALUE = dt2.Rows[0]["LAMS_CODE"].ToString();
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@REMARK ";
    paramobj.PARAMVALUE = txtremark.Text.ToString();
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    var msg=CommonClass.InsertData("PROC_LACNEW_UPDATE", objlist);
    var msgsplit = msg.Split('~');
    if (msgsplit[0] == "5")
    {
    ScriptManager.RegisterStartupScript(this, GetType(), "Myalert",
    "alert('" + CommonClass.AlertMessages(msgsplit[0]) + "');", true);
    clearform();
    }
    }
    protected void btncancel_Click(object sender, EventArgs e)
    {
    clearform();
    }
    private void clearform()
    {
    ddlvillagename.SelectedIndex = 0;
    ddllandclass.SelectedIndex = 0;
    txtlacno.Text = "";
    txtdt.Text = "";
    txtareainacre.Text = "";
    txtremark.Text = "";
    }
    protected void grdLacaseinput_RowEditing(object sender, GridViewEditEventArgs e)
    {
    populatevalue();
    grdLacaseinput.EditIndex = e.NewEditIndex;
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "openUpadteTab();", true);
    populateform();
    }
    protected void grdLacaseinput_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
    grdLacaseinput.EditIndex = -1;
    populatevalue();
    if (laccode == "")
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "opendefultTab();", true);
    Bindvillage();
    }
    else
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "openUpadteTab();", true);
    populateform();
    }
    }
    protected void grdLacaseinput_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    GridViewRow grdrow = (GridViewRow)grdLacaseinput.Rows[e.RowIndex];
    TextBox txtnotice = (TextBox)grdrow.FindControl("txtnotice");
    TextBox txtlamscode = (TextBox)grdrow.FindControl("txtlamscode");
    TextBox txtlamsseq = (TextBox)grdrow.FindControl("txtlamsseq");
    TextBox txtmadate = (TextBox)grdrow.FindControl("txtmadate");
    TextBox txtremark = (TextBox)grdrow.FindControl("txtremark");
    FileUpload flupld = (FileUpload)grdrow.FindControl("flupld");
    passvaluetoupdate(txtnotice.Text, txtlamscode.Text, txtlamsseq.Text, txtmadate.Text, txtremark.Text);
    populatevalue();
    if (flupld.FileName != "")
    {
    savefile(flupld, flupld.FileName);
    }
    populatevalue();
    if (laccode == "")
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "opendefultTab();", true);
    Bindvillage();
    }
    else
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "openUpadteTab();", true);
    grdLacaseinput.EditIndex = -1;
    populateform();
    }
    }
    private void passvaluetoupdate(string v1,string v2,string v3,string v4,string v5)
    {
    notification = v1;
    uplamscode = v2;
    uplamsseq = v3;
    upmadate = v4;
    upremark = v5;
    }
    // Code for the save uploaded file
    protected string documentupload(FileUpload id)
    {
    string Voucher_File = string.Empty;
    string msg = string.Empty;
    try
    {
    if (id.HasFile == true)
    {
    //string fileName = "PIC" + "-" + txtmobileno.Text.Trim().ToString() + Extension;

    string[] validFileTypes = { ".doc", ".pdf", ".docx", ".jpg", ".txt" };
    string Voucher_Filewithoutext = Path.GetFileNameWithoutExtension(id.PostedFile.FileName);
    string vcexten = Path.GetExtension(id.PostedFile.FileName);
    Stream strm = id.PostedFile.InputStream;
    decimal size = Math.Round(((decimal)id.PostedFile.ContentLength / (decimal)1024), 2);
    bool isValidFile = false;
    for (int i = 0; i < validFileTypes.Length; i++)
    {
    if (vcexten.ToLower().Equals(validFileTypes[i].ToLower()))
    {
    if (size > 10240)
    {
    msg = "1";
    isValidFile = false;
    break;
    }
    else
    {
    isValidFile = true;
    break;
    }
    }
    }
    //Guid.NewGuid()
    if (isValidFile)
    {
    dt = CommonClass.ViewDataWithOutConditon("select VILL_NAME from NEW_LA_CASE_MASTER where LAC_NO='"+ txtlacupdt.Text.ToString()+ "'");
    //Voucher_File = Voucher_Filewithoutext +"_"+txtlacupdt.Text.Substring(0,2)+"_"+ txtlacupdt.Text.Substring(3, 2) + "_"+notification.Substring(0,4)+ vcexten;
    Voucher_File = dt.Rows[0]["VILL_NAME"].ToString() + "_" + txtlacupdt.Text.Substring(0, 2) + "_" + txtlacupdt.Text.Substring(3, 2) + "_" + notification.Substring(0, 4) + vcexten;

    if (Voucher_File != "" && Voucher_File != string.Empty)
    {
    if (File.Exists(Server.MapPath("~/Application/Document/" + Voucher_File)))
    {
    File.Delete(Server.MapPath("~/Application/Document/" + Voucher_File));
    id.SaveAs(Server.MapPath("~/Application/Document/" + Voucher_File));
    }
    else
    {
    id.SaveAs(Server.MapPath("~/Application/Document/" + Voucher_File));
    }
    if (File.Exists(Server.MapPath("~/Application/Document/" + Voucher_File)))
    {
    return Voucher_File;
    }
    }
    else
    {
    Voucher_File = string.Empty;
    }
    }
    else
    {
    if (msg == "1")
    {
    Voucher_File = "1";
    }
    else
    {
    Voucher_File = "2";
    }
    }
    }
    }
    catch (Exception ex)
    {
    throw ex;
    }
    return Voucher_File;
    }
    public void LACase_Save(string file_name)
    {
    try
    {
    objlist = new List<CommonDTO>();
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAC_NO";
    paramobj.PARAMVALUE = lacno;
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAC_CODE";
    paramobj.PARAMVALUE = laccode;
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@C_STATUS";
    paramobj.PARAMVALUE = notification; // supplied from fetching outside
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@MA_DATE";
    paramobj.PARAMVALUE = upmadate; //supplied
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@REMARK";
    paramobj.PARAMVALUE = upremark; //supplied
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@REF_DOC";
    paramobj.PARAMVALUE = file_name.ToString();
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAMS_CODE";
    paramobj.PARAMVALUE = uplamscode; // supplied from fetching outside
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    paramobj = new CommonDTO();
    paramobj.PARAMNAME = "@LAMS_SEQ";
    paramobj.PARAMVALUE = uplamsseq; // supplied from fetching outside
    paramobj.PARAMTYPE = 2;
    objlist.Add(paramobj);
    CommonClass.InsertData("PROC_NEW_UPDATE_MILESTONE", objlist);
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }
    private void savefile(FileUpload flupload,string filename)
    {
    string msg = string.Empty;
    if (filename != "")
    {
    msg = documentupload(flupload);
    }
    if (msg == "1")
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('File size should be less than 10MB');", true);
    }
    else if (msg == "2")
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('Please upload document file only');", true);
    }
    else
    {
    LACase_Save(msg);
    }
    }
    protected void grdLacaseinput_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    if (e.Row.RowState != DataControlRowState.Edit)
    {
    LinkButton lnkrefdoc = (LinkButton)e.Row.FindControl("lnkrefdoc");
    LinkButton lnkbtnupdate = (LinkButton)e.Row.FindControl("lnkbtnupdate");
    LinkButton lnkbtnreqst = (LinkButton)e.Row.FindControl("lnkbtnreqst");
    if (lnkrefdoc.Text != "NO RECORD")
    {
    lnkbtnupdate.Visible = false;
    lnkbtnreqst.Visible = true;
    }
    else
    {
    lnkbtnupdate.Visible = true;
    lnkbtnreqst.Visible = false;
    }
    }
    }
    }
    protected void grdLacaseinput_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    if (e.CommandName == "viewdocmnt")
    {
    GridViewRow grdrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
    LinkButton lnkrefdoc= (LinkButton)grdrow.FindControl("lnkrefdoc");
    string serverpath = "~Document/" + lnkrefdoc.Text.ToString();
    hdnPrintdoc.Value = lnkrefdoc.Text.ToString();
    Page.ClientScript.RegisterStartupScript(typeof(Page), "msg", "<script type='text/javascript'>ShowInsuranceDoc()</script>");
    populatevalue();
    if (laccode == "")
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "opendefultTab();", true);
    Bindvillage();
    }
    else
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "openUpadteTab();", true);
    populateform();
    }
    }
    }
    }
    }

    //storedprocdures

    USE [OCPL_DB]
    GO
    /****** Object: StoredProcedure [dbo].[PROC_NOTICE_ABSTRACT] Script Date: 12-03-2018 16:06:10 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    ALTER PROC [dbo].[PROC_NOTICE_ABSTRACT] (@LAND_CATG VARCHAR(50),@LAC_CODE VARCHAR(50))
    AS
    BEGIN
    TRUNCATE TABLE TEMP_NOTICE
    DECLARE @NOTICE_TEMP varchar(100),@NOTICE varchar(100),@MA_DATE varchar(50),@REMARK varchar(500),@REF_DOC varchar(50),@LAMS_CODE varchar(50);
    DECLARE @LAMS_SEQ int;
    DECLARE NOTICE CURSOR FOR SELECT LAMS_CODE FROM MILESTONE_MASTER WHERE LAND_CATG=@LAND_CATG;
    OPEN NOTICE
    FETCH NEXT FROM NOTICE INTO
    @NOTICE
    WHILE @@FETCH_STATUS = 0
    BEGIN
    SELECT @NOTICE_TEMP= (SELECT LA_MS FROM MILESTONE_MASTER WHERE LAND_CATG=@LAND_CATG AND LAMS_CODE=@NOTICE)
    SELECT @LAMS_CODE= (SELECT LAMS_CODE FROM MILESTONE_MASTER WHERE LAND_CATG=@LAND_CATG AND LAMS_CODE=@NOTICE)
    SELECT @LAMS_SEQ= (SELECT LAMS_SEQ FROM MILESTONE_MASTER WHERE LAND_CATG=@LAND_CATG AND LAMS_CODE=@NOTICE)
    SELECT @MA_DATE= (SELECT MA_DATE FROM MILESTONE_DETAIL WHERE LAC_CODE=@LAC_CODE AND LAMS_CODE=@NOTICE)
    SELECT @REMARK= (SELECT REMARK FROM MILESTONE_DETAIL WHERE LAC_CODE=@LAC_CODE AND LAMS_CODE=@NOTICE)
    SELECT @REF_DOC= (SELECT REF_DOC FROM MILESTONE_DETAIL WHERE LAC_CODE=@LAC_CODE AND LAMS_CODE=@NOTICE)
    IF(@REF_DOC IS NOT NULL)
    BEGIN
    INSERT INTO TEMP_NOTICE(NOTICE_TEMP,LAMS_CODE,LAMS_SEQ,MA_DATE,REF_DOC,REMARK) VALUES(@NOTICE_TEMP,@LAMS_CODE,@LAMS_SEQ,@MA_DATE,@REF_DOC,@REMARK);
    END
    ELSE
    BEGIN
    SET @REF_DOC='NO RECORD';
    INSERT INTO TEMP_NOTICE(NOTICE_TEMP,LAMS_CODE,LAMS_SEQ,MA_DATE,REF_DOC,REMARK) VALUES(@NOTICE_TEMP,@LAMS_CODE,@LAMS_SEQ,@MA_DATE,@REF_DOC,@REMARK);
    END
    FETCH NEXT FROM NOTICE INTO
    @NOTICE
    END
    CLOSE NOTICE
    DEALLOCATE NOTICE

    SELECT * FROM TEMP_NOTICE

    END

    Monday, March 12, 2018 11:20 AM

All replies

  • User-1838255255 posted

    Hi chandan01,

    According to your description and exception message, I guess you insert the null data to database, so caused this issue. But i am not clear which line code caused this issue, but i think you could handle data with the following code: 

    if ((string.IsNullOrEmpty(textboxID.Text.ToString().Trim) == true)) {
        frmFirstName = DBNull.Value;
    }
    else {
        frmFirstName = textboxID.Text;
    }
    

    For more details, please check the following tutorial:

    https://msdn.microsoft.com/en-us/library/system.dbnull.value.aspx?f=255&MSPPError=-2147217396 

    Best Regards,

    Eric Du 

    Tuesday, March 13, 2018 6:20 AM
  • User-1716253493 posted

    There is Insert/Edit code sample "{;}" icon feature here.

    Please edit your post, place the codes in code sample block, see "{;}" icon

    Sparate the codes into 3 blocks, html, c#, sp

    Tuesday, March 13, 2018 9:03 AM