I am Using asp.net grid view and i have one column in that namely Calories and i want to show whole caloreis total at the top. i used the following code:
int count = grdViewSample.Rows.Count;
double totCalories = 0;
Label lblCalories = new Label();
foreach (GridViewRow row in grdViewSample.Rows)
{
lblCalories = (Label)row.FindControl("lblCalories");
totCalories = totCalories + Convert.ToDouble(lblCalories.Text);
}
lblTotalCaloreis.Text = lblTotalCaloreis.Text + " " + totCalories;
and my problem is that the calories total get changed by paging and i want total caloreies available in grid view.
Thanks
Instated of using
grid view row property retrive no of rows from the data set directly because row property changes with the paging
foreach (DataRow row in dsFood.Tables[0].Rows)
{
totCal += Convert.ToDouble(row["calories"]);
}
lblCalories.Text = " " + totCal;
Related
i have this code
MasterSoapClient sp = new MasterSoapClient();
MasterData[] lstMasterData = sp.GetActivityType(stid, null, 1);
grdEditActivityType.DataSource = lstMasterData;
grdEditActivityType.DataBind();
Session["opType"] = 2;
txtActivityCode.Text = lstMasterData.ToString();
txtActivityCode.DataBind();
here i called web service and put all data in this Gridview "grdEditActivityType "
and already workin
but there is column of lstMasterData i want to put it in the text box out of the grid
how i can do this ?
txtActivityCode.Text is a Property that you can use to assign a text value to the TextBox.
If you use txtActivity.Text = " some input "; Your textbox will contain the text " some input ".
You don't need to Bind txtActivityCode afterwards.
Having this clarified the next step is to create the string you want using to assign to the text box.
string s = "";
foreach( var masterData in lstMasterData )
{
s += masterData.SomeProperty; // s += masterData.ToString(); maybe, it depends on what do you want to put in the textbox;
}
txtActivityCode.Text = s;
And that's all.
I would suggest to start look more over ASP.NET tutorials to understand better how this framework works.
My page has a chart that is set up to display data that is coming from a SqlDataSource.
There is a TreeView which contains a list of datapoints that I want to be able to add to the chart as different series. The user selects which item they wish to add by clicking a checkbox in the treeview for that node and then clicks an update button to refresh the chart.
Each node's value is set to a column name in the table.
If there is only one point selected on the treeview the data comes across as a series on the chart with no problem when the update button is clicked.
If multiple items in the treeview are selected an ASP.NET error page appears when clicking the button stating that a column name 'XXXX' was not found where 'XXXX' is the node.Value of the highest item in the tree that was checked.
For example an error saying that "Column with name 'X1' was not found" would show up when using the following selection:
If just 'X1' is checked the data shows up on the chart.
public void UpdateChart(Object sender, EventArgs e)
{
if (TagTreeView.CheckedNodes.Count > 0)
{
foreach (TreeNode node in TagTreeView.CheckedNodes)
{
// Add a series to the chart
Series series = new Series();
series=Chart1.Series.Add("Series"+node.Value);
series.ChartArea = "ChartArea1";
series.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), charts[1], true);
// create a datasource, add it to the page,
SqlDataSource sqlDataSource = new SqlDataSource();
sqlDataSource.ID = "SQLDataSource"+node.Value;
sqlDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["HistoricalDataConnectionString"].ConnectionString;
if (node.Depth > 1)
{
if (node.Parent.Text.Contains("AAA"))
{
MessageBox.Show(node.Value);
sqlDataSource.SelectCommand = "SELECT (Date + CONVERT(datetime,Time)) As TimeStamp, " + node.Value + " FROM AAA ORDER BY TimeStamp";
}
this.Page.Controls.Add(sqlDataSource);
Chart1.DataSourceID = "SQLDataSource"+node.Value;
Chart1.Series["Series" + node.Value].XValueMember = "TimeStamp";
Chart1.Series["Series" + node.Value].YValueMembers = node.Value;
Chart1.DataBind();
}
}
}
}
Is there a way to take each selected item in the TreeView and use the node.value to build a query to add an additional series to the chart? I have done a little bit of work to see if putting the SqlDatasource and Series objects into an array and looping through that but it doesn't seem to be taking me anywhere.
To get this to work correctly all of the datapoints that will be added to the chart need to be included in the select statement for the sqlDataSource:
sqlDataSource.SelectCommand = "SELECT (Date + CONVERT(datetime,Time)) As TimeStamp, X1, X2, X3 FROM AAA ORDER BY TimeStamp";
How to show pop up menu from database in gridview on each gridview row items ?
Example of this is :
http://www.redbus.in/Booking/SelectBus.aspx?fromCityId=733&fromCityName=Delhi&toCityId=757&toCityName=Manali&doj=26-Dec-2010&busType=Any
Move your cursor to Departure time and arrival time...a want this type of popup in gridview items....which fetch entries from database..
You can handle this with javascript/jQuery. The gridview itself has nothing to do with this.
If I was going to build what he has just by looking at it I would create the table dynamically. This way you could use a string builder and insert variable names in between each td tag. You retrieve all your data from the database and store in a List or even better use LINQ to SQL.
I wish I could give you a sample in VB, but here is an example of what I'm talking about.
protected void Page_Load(object sender, EventArgs e)
{
StoreDataContext db = new StoreDataContext();
var join = from b in db.Brands
select new
{
Brand = b,
c = b.Description.Length < 204 ? b.Description : b.Description.Substring(0, 204) + "...",
Sources =
from s in db.Sources
join xref in db.Brands_Sources on s.SourceID equals xref.SourceID
where xref.BrandID == b.BrandID
select s
};
StringBuilder sb = new StringBuilder();
sb.Append( "<table class='tableStripe'>");
sb.Append( "<tr><th width='1%'>Active</th><th>Image</th><th>Name</th><th>Short Description</th><th>Source</th><th width='1%'>Date Created</th><th width='1%'>Data Modified</th></tr>");
foreach (var result in join)
{
string chk = (result.Brand.Active ? "checked='checked'" : "");
sb.AppendFormat( "<tr><td><input class='brandChk' value='{4}' type='checkbox' {0}></td><td width='1%'><img width='50px' src='{1}'</img></td>" +
"<td><a href='/admin/Catalog/Brand/Detail.aspx?brandId={4}'>{2}</a></td><td width='60%'>{3}</td>", chk, result.Brand.Image, result.Brand.Name, result.c,result.Brand.BrandID);
sb.Append("<td>");
foreach (var q in result.Sources)
{
string srcname = (q.Source1=="Motovicity" ? "Motovicity":"Direct");
sb.AppendFormat("<img src='{0}' title='{1}'</img>", q.Image,srcname);
}
string date = string.Format("{0:MM/dd/yy}", result.Brand.DateCreated);
string mod = string.Format("{0:MM/dd/yy}", result.Brand.DateModified);
sb.Append("</td>");
sb.AppendFormat("<td>{0}</td><td>{1}</td></tr>", date, mod);
}
sb.Append("</table>");
resultSpan.InnerHtml = sb.ToString();
}
As you can see I code the html for a checkbox and insert the brand id into the value attribute.
He is not fetching record on runtime basically if you see the structure he has the information in the tooltip attribute of anchor tag and using jquery cluetip to display it.
so you can use any jquery tooltip plugin to display same as he is doing.
Thanks
In the asp.net dropdownlist i need to trim the data inside the list. e.g if my drop down has 10 records in it and i only want to show the first 20 chars of each record, then how do i do it?. Also if records are only 10 chars then from 20 chars the dropdownlist should automatically resize to 10 chars. any ideas?
If you can't trim the data at the source (i.e. the database query or wherever you're getting the data from), then you can just modify the data after the dropdown has been databound.
myDropDown.DataBind();
foreach (var item in myDropDown.Items)
{
if (item.Text.Length > 20)
{
item.Text = item.Text.Substring(0, 10);
}
}
I can't recall if the ASP.NET version has a Tag property but if it does this would shorten the text and preserve the original value (copied original from womp):
myDropDown.DataBind();
foreach (var item in myDropDown.Items)
{
if (item.Text.Length > 20)
{
item.Tag = item.Text;
item.Text = item.Text.Substring(0, 10);
}
}
If not then maybe Attributes (forgive me if my syntax is off, no compiler here to verify against):
myDropDown.DataBind();
foreach (var item in myDropDown.Items)
{
if (item.Text.Length > 20)
{
item.Attributes["title"] = item.Text;
item.Text = item.Text.Substring(0, 10);
}
}
suppose consider in datagrid i have two text box when i fill records to it then i ill press tab key then another row automatically generated so how can i delete multiple rows using checkbox in datagrid not in gridview
int i = (DataGridView1.Rows.Count - 1); while ((i >= 0)) { i = (i -
1); foreach (DataGridViewRow dr in DataGridView1.Rows) { if
(dr.Cells("check").Value == false) {
DataGridView1.Rows.Remove(dr); } } }