[WebMethod]
public static string DeletePrescription(int PrescriptionId)
{
BusinessLogicLayer objBusiness = new BusinessLogicLayer();
SanatanJeevanBusinessObjects.Prescription objPrescription = new SanatanJeevanBusinessObjects.Prescription();
objPrescription.PrescriptionId = Convert.ToInt32(PrescriptionId);
objBusiness.DeletePrescriptionBAL(objPrescription);
DataSet ds = new DataSet();
ds = objBusiness.GetPrescription(objPrescription);
listPreDetails.DataSource = ds;
listPreDetails.DataBind();
return "success";
}
hi,
i am using ajax function to delete a row after delete the row in the table bind the data in listview. please help me.
Although youll be deleting the item in the code behind it will still stay on the page because theres no way of interacting with your controls on the page
I have similar requirements but then remove the parent row from the screen using the JQuery below.
function Delete(idToDelete) {
var par = $(this).parent().parent(); //tr
var id;
if (idToDelete.selector == undefined) {
if (!$(this.id).selector == "") {
id = $(this.id).selector;
} else {
id = idToDelete;
}
} else {
id = idToDelete;
}
par.remove();
};
This works for me every time now.
Related
For my application there are a few separate dataTables and I need to create a new dataTable based on matching ids. I have to do the process a few times so I created a function so I'm not duplicating code, I've done this like so:
private static DataTable CloneTable(DataTable originalTable, DataTable newTable, DataTable targetTable,
string addedColumn, string columnToExtract, bool multipleConditions = false, string secondColumnName = null, string secondColumnConditon= null)
{
newTable = originalTable.Clone();
newTable.Columns.Add(addedColumn);
foreach (DataRow row in originalTable.Rows)
{
DataRow[] rowsTarget;
if (multipleConditions == false)
{
rowsTarget = targetTable.Select(string.Format("ItemId='{0}'", Convert.ToString(row["ItemId"])));
} else
{
rowsTarget = targetTable.Select(string.Format("ItemId='{0}' AND {1} ='{2}'", Convert.ToString(row["ItemId"]), secondColumnName, secondColumnConditon));
}
if (rowsTarget != null && rowsTarget.Length > 0)
{
string data = rowsTarget[0][columnToExtract].ToString();
var lst = row.ItemArray.ToList();
lst.Add(data);
newTable.Rows.Add(lst.ToArray());
}
else
{
string data = "";
var lst = row.ItemArray.ToList();
lst.Add(data);
newTable.Rows.Add(lst.ToArray());
}
}
return newTable;
}
I then call this in a separate function like so:
private DataTable GetExtractData()
{
.........................
DataTable includeLastModified = new DataTable();
DataTable includeFunction = new DataTable();
DataTable includeDiscipline = new DataTable();
CloneTable(itemsTable, includeLastModified, lastModifiedTable, "LastModifiedDate", "LastModifiedDate");
CloneTable(includeLastModified, includeFunction, customPropertiesTable, "Function", "ItemTitle", true, "Title", "Function");
CloneTable(includeFunction, includeDiscipline, customPropertiesTable, "Discipline", "ItemTable", true, "Title", "Discipline");
return includeDiscipline;
}
The issue I am having is that the dataTable here is returning empty and I am not sure why.
In my CloneTable function I did the following to make sure that the new table is not empty:
foreach (DataRow row in newTable.Rows)
{
foreach (var item in row.ItemArray)
{
Console.WriteLine(item);
}
}
It is not empty so I am not sure why when I'm returning it in a separate function it is now empty?
I call the same thing but for the includeDiscipline table in the GetData function but it comes back empty.
There are no errors but there is a message that comes and goes that says that the parameter "newTable" can be removed as the initial value isn't used. I'm not sure how that could be the case though as it is clearly being used?
I'm assuming that it is probably the way I am calling the function but I'm really not sure what it is that I have done wrong here
Okay face palm moment, just realised I forgot to assign it to something.
So if I do something like:
var test = CloneTable(itemsTable, includeLastModified, lastModifiedTable, "LastModifiedDate", "LastModifiedDate");
return test;
It works fine and no longer returns empty
I have gridview which I need to populate the data by selecting the value from dropdownlist.
For this I am trying to update a stored procedure with a parameter. We are using Entity Framework database access.
But I'm not getting any results to the gridview, after I change the stored procedure.
Can anyone please help me?
public DataView BindReport()
{
var user = Session["currentUser"] as UserSession;
if (user == null)
return null;
var totalrows = 0;
var result = SalesReport.GetJobseekerReportResults(user.CompanyId,ref totalrows);
DataView ds = ToDataTable(result).DefaultView;
if (ViewState["SortExpr"] != null)
ds.Sort = ViewState["SortExpr"].ToString();
RowCount = totalrows;
dataTable = new DataTable();
dataTable = ds.ToTable();
return ds;
}
private void InitializePageSize(GridView gridView)
{
var user = Session["currentUser"] as UserSession;
if (user == null)
return;
var pageSize = GridController.GetGridSizeForUser(user.UserId, gridView.ID, user.CompanyId);
if (pageSize == null)
return;
gridView.PageSize = (int)pageSize.page_size;
ddlSkillPageCount.SelectedValue = gridView.PageSize.ToString(CultureInfo.InvariantCulture);
gridView.DataBind();
}
public static List<JobseekerReport_Result> GetJobseekerReportResults(long companyid, ref int tototalrows)
{
var context = new NavDataEntities();
List<JobseekerReport_Result> result = null;
try
{
context.Database.Connection.Open();
result = context.JobseekerReport(companyid).ToList();
}
catch (Exception)
{
}
finally
{
context.Database.Connection.Close();
}
return result;
}
public virtual ObjectResult<JobseekerReport_Result> JobseekerReport(Nullable<long> cmpid)
{
var cmpidParameter = cmpid.HasValue ?
new ObjectParameter("cmpid", cmpid) :
new ObjectParameter("cmpid", typeof(long));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<JobseekerReport_Result>("JobseekerReport", cmpidParameter);
}
private void InitializePageSize(GridView gridView)
{
var user = Session["currentUser"] as UserSession;
if (user == null) return;
var pageSize = GridController.GetGridSizeForUser(user.UserId, gridView.ID, user.CompanyId);
if (pageSize == null) return;
gridView.PageSize = (int)pageSize.page_size;
ddlSkillPageCount.SelectedValue = gridView.PageSize.ToString(CultureInfo.InvariantCulture);
DataSet ds = BindReport(); /// Added these two lines.
gridView.DataSource = ds; ///
gridView.DataBind();
}
I got the results. And now gridview is populating the results when the dropdownlist value selected.
The problem i got is with edmx model. When ever i do changes in tables or stored proc. First i need to delete the edmx model from solution and then add it again.
Thank you.
I've searched all over here and Google and still can't find an answer to this. I'm playing around with Amazon's API and am making a simple Windows Form to try and display the data in a DataGridView. The GridView is generating 10 rows for the 10 results I am getting, but is not filling the rows with the actual data. They're just blank.
The code below is a method (GetResults) that return a DataTable. I didn't show all of it because there is a bunch of code above to get the data.
DataTable dt = new DataTable();
dt.Columns.Add("ASIN", typeof(string));
dt.Columns.Add("Title", typeof(string));
// write out the results
foreach (var item in response.Items[0].Item)
{
Product product = new Product(item.ASIN, item.ItemAttributes.Title);
Console.WriteLine(product.ASIN);
var dr = dt.NewRow();
dr["ASIN"] = product.ASIN;
dr["Title"] = product.Title;
dt.Rows.Add();
}
return dt;
}
private void btnSearch_Click(object sender, EventArgs e)
{
dgvProducts.AutoGenerateColumns = false;
dgvProducts.DataSource = GetReults();
}
I know it is getting the info because I am writing it to console and it is showing up correctly.
I also have this basic class for the Product:
public class Product
{
private string asin;
private string title;
public Product() { }
public Product(string newAsin, string newTitle)
{
this.asin = newAsin;
this.title = newTitle;
}
public string ASIN
{
get { return asin; }
set { asin = value; }
}
public string Title
{
get { return title; }
set { title = value; }
}
I've tried setting AutoGenerateColumns = false and setting the column data bindings myself, but that didn't do anything either.
You're adding an empty row to the table, not adding your newly created row.
Change
dt.Rows.Add();
To
dt.Rows.Add(dr);
I am using ObjectListView to display information regarding virtual machines and each virtual machine has a different set of drives attached to it. During my data gathering, I get all of the info and store it in a Disk_Drive object with the properties that I care for (size,serial,usage,etc), now I want to dynamically create the columns and then bind the data using AddObjects. How would I do this?
I am not sure what the aspect getter should be in this scenario as it will not be unique, how can I handle this?
public void GenerateColumns(Model.HyperVTools.VMInfo vmObject)
{
objectListView2.Columns.Clear();
objectListView2.Items.Clear();
List<OLVColumn> columnsList = new List<OLVColumn>();
OLVColumn vmhostnameColumn = new OLVColumn("Hostname", "Host");
//vhd columns
foreach (var disk in vmObject.DisksList)
{
string text = string.Format("{0};{1}GB;{2}GB;", disk.Path, disk.SizeReadable,
disk.MaxVHDSizeReadable);
disk.FormattedVHDInfo = text;
OLVColumn diskColumn = new OLVColumn("Attached VHD", "FormattedVHDInfo");
columnsList.Add(diskColumn);
}
columnsList.Add(vmhostnameColumn);
objectListView2.Columns.AddRange(columnsList.Cast<System.Windows.Forms.ColumnHeader>().ToArray());
objectListView2.AddObject(vmObject);
}
Try this:
DataTable dtInput = new DataTable();
dtInput = dsAnalystPage.Tables[0];
foreach (DataColumn cl in dtInput.Columns)
{
BrightIdeasSoftware.OLVColumn aNewColumn = new BrightIdeasSoftware.OLVColumn();
aNewColumn.Name = cl.ColumnName;
aNewColumn.Text = cl.ColumnName;
if (aNewColumn.Text == "ASF_Code" || aNewColumn.Text == "ASD_SheetCode" || aNewColumn.Text == "ASD_SheetName")
{
aNewColumn.Width = 0;
aNewColumn.IsVisible = false;
}
OLV.AllColumns.Add(aNewColumn);
OLV.RebuildColumns();
}
Try resetting the control.
OLV.Reset();
In my dataset I have many rows,
In first row last column has the value is "12356.56#Firefox 1#23423"
In Second row same column has the value is "12356.56#Chrome2.0#23423"
In Third row same column has the value is "3423#Firefox 14.0#sdfsd"
here instead of displaying same value like above..
I need to display just "Firefox" if that column has Firefox in UI
I need to display just "Chrome" if that column has Chromein UI
how can i do it...
Use this helper function
public static string GetBrowser(string str)
{
str = str.ToUpper();
if(str.Contains("CHROME"))
{
return "Chrome";
}
else if(str.Contains("FIREFOX"))
{
return "Firefox";
}
return "Unknown";
}
Then when you bind the dataset to the UI use it to display the value.
If you have a list of things you want to check for, you can use .Contains to check:
var myValue = myDS[rowIndex][lastColumn].ToString();
if (myValue.Contains("Firefox"))
return "Firefox";
else if (myValue.Contains("Chrome"))
return "Chrome";
else
return "Unknown";
Demo: http://ideone.com/pMVeD
From the examples you've given, it appears the following logic may work, but it should be tested against a wider variety of sample values:
var myValue = myDS[rowIndex][lastColumn].ToString();
var parts = myValue.Split('#');
var browser = parts[1].Split(' ','0','1','2','3','4','5','6','7','8','9');
return browser[0];
Demo: http://ideone.com/NrY1e
Here is code. This might help.
DataSet ds = new DataSet();
//DataTable dt = new DataTable();
ds.Tables.Add("table0");
DataColumn dc = new DataColumn("browser");
ds.Tables[0].Columns.Add(dc);
ds.Tables[0].Rows.Add("12356.56#Firefox1#23423");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string str = ds.Tables[0].Rows[i][0].ToString();
if((str.ToLower().CompareTo("firefox"))!=0)
{
ds.Tables[0].Rows[i][0] = "firefox";
}
}
_gridView.DataSource = ds;
_gridView.DataBind();