private void BindGrid() { Int64 intFromCityIdno = Convert.ToInt64(ddlFromCity.SelectedValue); Int64 intToCityIdno = Convert.ToInt64(ddlToCity.SelectedValue); DistanceMastDAL objItemMast = new DistanceMastDAL(); var lstGridData = objItemMast.SelectForSearch(intFromCityIdno, intToCityIdno); objItemMast = null; if (lstGridData != null && lstGridData.Count > 0) { DataTable dt = new DataTable(); dt.Columns.Add("SrNo", typeof(string)); dt.Columns.Add("FromCity", typeof(string)); dt.Columns.Add("ViaCity", typeof(string)); dt.Columns.Add("ToCity", typeof(string)); dt.Columns.Add("Kms", typeof(string)); dt.Columns.Add("Status", typeof(string)); for (int i = 0; i < lstGridData.Count; i++) { DataRow dr = dt.NewRow(); dr["SrNo"] = Convert.ToString(i + 1); dr["FromCity"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "FromCityName")); dr["ViaCity"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "ViaCityName")); dr["ToCity"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "ToCity")); dr["Kms"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "KMs")); dr["Status"] = Convert.ToBoolean(DataBinder.Eval(lstGridData[i], "Status")) == true ? "Active" : "InActive"; dt.Rows.Add(dr); } if (dt != null && dt.Rows.Count > 0) { ViewState["Dt"] = dt; } // grdMain.DataSource = lstGridData; grdMain.DataBind(); lblTotalRecord.Text = "T. Record (s): " + lstGridData.Count; int startRowOnPage = (grdMain.PageIndex * grdMain.PageSize) + 1; int lastRowOnPage = startRowOnPage + grdMain.Rows.Count - 1; lblcontant.Text = "Showing " + startRowOnPage.ToString() + " - " + lastRowOnPage.ToString() + " of " + lstGridData.Count.ToString(); lblcontant.Visible = true; divpaging.Visible = true; imgBtnExcel.Visible = true; } else { grdMain.DataSource = null; grdMain.DataBind(); lblTotalRecord.Text = "T. Record (s): 0 "; lblcontant.Visible = false; divpaging.Visible = false; imgBtnExcel.Visible = false; } }
protected void lnkbtnSave_OnClick(object sender, EventArgs e) { Int32 empIdno = Convert.ToInt32((Session["UserIdno"] == null) ? "0" : Session["UserIdno"].ToString()); int IntValue = 0; if (IsValid) { if (ddlFromCity.SelectedValue != ddlToCity.SelectedValue) { using (TransactionScope Tran = new TransactionScope(TransactionScopeOption.Required)) { DistanceMastDAL objDAL = new DistanceMastDAL(); if (Convert.ToString(hidDisMastIdno.Value) == "") { IntValue = objDAL.Insert(Convert.ToInt64(ddlFromCity.SelectedValue), Convert.ToInt64(ddlToCity.SelectedValue), Convert.ToInt64(txtkms.Text.Trim()), chkStatus.Checked, Convert.ToInt64(ddlViaCity.SelectedValue), empIdno); } else { IntValue = objDAL.Update(Convert.ToInt64(hidDisMastIdno.Value), Convert.ToInt64(ddlFromCity.SelectedValue), Convert.ToInt64(ddlToCity.SelectedValue), Convert.ToInt64(txtkms.Text.Trim()), chkStatus.Checked, Convert.ToInt64(ddlViaCity.SelectedValue), empIdno); } if (IntValue > 0 && Convert.ToString(hidDisMastIdno.Value) == "") { Tran.Complete(); ShowMessage("Record Save Successfully."); Clear(); lnkbtnNew.Visible = false; } else if (IntValue > 0 && Convert.ToString(hidDisMastIdno.Value) != "") { Tran.Complete(); ShowMessage("Record Update Successfully."); Clear(); lnkbtnNew.Visible = false; } else if (IntValue == -1) { Tran.Dispose(); ShowMessageErr("Record already Exist."); } else { Tran.Dispose(); ShowMessageErr("Record Not Save."); } } } else { ShowMessageErr("From City & To City Can not Same."); } } }
private void Populate(int ItemIdno) { DistanceMastDAL objDistMast = new DistanceMastDAL(); var objDistanceMast = objDistMast.SelectById(ItemIdno); objDistMast = null; if (objDistanceMast != null) { ddlFromCity.SelectedValue = Convert.ToString(objDistanceMast.FrmCity_Idno); ddlToCity.SelectedValue = Convert.ToString(objDistanceMast.ToCity_Idno); ddlViaCity.SelectedValue = Convert.ToString(objDistanceMast.ViaCity_Idno); txtkms.Text = Convert.ToString(objDistanceMast.KMs); chkStatus.Checked = Convert.ToBoolean(objDistanceMast.Status); hidDisMastIdno.Value = Convert.ToString(objDistanceMast.Distance_Idno); } }
protected void grdMain_RowCommand(object sender, GridViewCommandEventArgs e) { Int32 empIdno = Convert.ToInt32((Session["UserIdno"] == null) ? "0" : Session["UserIdno"].ToString()); string strMsg = string.Empty; if (e.CommandName == "cmdEdit") { Response.Redirect("DistanceMast.aspx?DistmastId=" + e.CommandArgument, true); } else if (e.CommandName == "cmdstatus") { int intitemIdno = 0; bool bStatus = false; string[] strStatus = Convert.ToString(e.CommandArgument).Split(new char[] { '_' }); if (strStatus.Length > 1) { intitemIdno = Convert.ToInt32(strStatus[0]); if (Convert.ToBoolean(strStatus[1]) == true) { bStatus = false; } else { bStatus = true; } DistanceMastDAL objItemMast = new DistanceMastDAL(); int value = objItemMast.UpdateStatus(intitemIdno, bStatus, empIdno); objItemMast = null; if (value > 0) { this.BindGrid(); strMsg = "Status updated successfully."; ddlFromCity.Focus(); } else { strMsg = "Status not updated."; } ScriptManager.RegisterStartupScript(this, this.GetType(), "alertstrMsg", "PassMessage('" + strMsg + "')", true); } } else if (e.CommandName == "cmddelete") { DistanceMastDAL objItemMast = new DistanceMastDAL(); long intValue = objItemMast.Delete(Convert.ToInt32(e.CommandArgument)); objItemMast = null; if (intValue > 0) { this.BindGrid(); strMsg = "Record deleted successfully."; ddlFromCity.Focus(); } else { if (intValue == -1) { strMsg = "Record can not be deleted. It is in use."; } else { strMsg = "Record not deleted."; } } ScriptManager.RegisterStartupScript(this, this.GetType(), "alertstrMsg", "PassMessage('" + strMsg + "')", true); } }