good day gurus!
I'm new to ASP.NET and I'm still in the process of learning it.
I was able to finish a couple of aspx pages through searching google but I can't seem to get this one page to work.
Basically, I'm trying to display a table (data fetched from SQL table).
All data are fetched from SQL table except for these static cells:
Item | Jan | Feb | March | April | Total
Sponge | Rod | Clock | Paper | Prod Cost | Profit
(and all the SUMS)
The "Adjust1" is inserted there if its values are not null. And this "Adjust1" also affects the "Total".
I hope someone can point me to the right direction.
Thanks a lot for your time,
Pod
use gridview template feild, just not bind data to your static feild
You can bind your dataset directly to a GrdiView control, and without much manipulation, it will output the columns and rows exactly like your dataset that you returned from the DB.
However, I'm not clear as to what you mean to do with the 'Adjust1' row. Can you explain this in a little more detail?
for the sql manipulation it will be much easier and clean, and create the dataset such a way that it look a like the gridview. This will be a more flexible approach as in future if you want to change any header say display January in place of Jan you dont need any new publish but just a sp update in database
I still you do not want to go with db you can any time achieve this task by using grid rowbound event. Add template fields for calculated columns like total, for displaying the header such jan,feb you can use the headertext property of bound field. For add the value in item field you can pass -1 in the dataset and while bound the grid based on the row index replace the text with required values.
for more details on row databound event read this http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
Related
I have a datatable in code. And the datagridview in the Ui.
In code I have done gridviewName.DataSource = dtTable1
Now in the UI I can see gridview populated with the table data. In the UI gridview I can update the cell values and/or delete the data rows. Upon doing any changes to the gridview, the changes automatically flow back into the data table.
I am bit confused at this point because I had thought it is a 1 way connection from data table into datagridview. Is this 2 way by design? If yes, then subsequently if I want to perform an operation per row, like send an email per row, then it is recommended to iterate over the gridview or the data table?
Yes, the 2 way data flow is by design; it makes creating applications a lot easier. If you don't want your user to edit a grid you make the grid read only, but typically you show data to a user, you let them edit it and save it. That would get a lot more hard work if you made data binding a one way thing the grid is connected to the datatable directly; it doesn't copy the data it finds into its own internal data array
Always loop over the datatable, read it and edit it directly; the grid will update accordingly; always avoid looping over the datagridview. As the embodiment of model-View-controller your code should manipulate the model (datatable) not try and manipulate the model via the view/controller that is intended for the user (the datagridview)
If you add a DataSet type file to your project and design a strongly typed datatable inside it your life gets easier. Your code looks like:
foreach(var r in soneDataset.EmailQueueDataTable){
mailer.Send(r.From, r.To, r.Subject, r.Message, r.RetryAttempts);
}
With a standard datatable everything is done with string column names or worse, ordinal positions and needs casting:
foreach(DataRow r in EmailQueueDataTable.Rows){
mailer.Send((string)r["From"], (string)r["To"], (string)r["Sujbect"], (string)r["Message"], (int)r["RetryAttempts"]);
}
Intellisense won't help you with the column names either; you'll only find out at runtime that I made a typo in Subject
I have a DataGridView which is bound to a datasource dtDataMain , I have roughly 18 columns - the last two columns 17 and 18 are merged into the dtDataMain (if that matters to some one).
I also have a checkedlistbox which is a representation of selected items in an intermediary table dtSelections.
I have some pseudo code:
dtDataMain.Merge(dtSelections, MissingSchemaAction.AddWithKey)
MyDataGridViewBindingSource.DataSource = dtDataMain
MyDataGridView.DataSource = MyDataGridViewBindingSource
I merged the two tables because I wanted the database to provide the initial csv(Comma Separated Values) data that will populate all of the rows of the datagridview.
I use a checkedlistbox for the possible selections that make up that csv text and depending on my checked or not checked status I set the values in the datgridview cells and also in my bindingsource.
My Problem here is datgridview fires databinding complete - which I do not want it to do. Is there any way that I can accept changes in the COLUMN 17 and 18 of the row - and any changes in the rest of the columns are persisted?
EDIT 1: 9/27/2016
I need to add this here as it is too lengthy for the comment field:
I know the rows have changed since I merged the tables I acceptChanges on the merged table (lefthandside) to clear that.
I ran getChanges to verify all was good - no changes. I add the datasource to the dataGridView - it binds and then fires the bindingcomplete event,
in the bindingcomplete event I find that somehow 2 rows changed row(0)
and Row(1) - there are 30 rows. I do not know why this happens.
So I am trying to decouple the columns that I merged from the DataGridView , I merged them because the SQL server supplies the CSV nicely,and when I save the data the DataGridView comes back with those two added columns with data.
Previously with the two columns unbound when I did a save of the data the datagridview would not show the unbound data - just empty columns. That means every save I have to write all the rows of data in the format and order just like I am getting from the db and I also need to do it on every load and make sure it is synced with the data in each of those rows. Which is the reason for my strange question. I also have controls bound to the datasource.
So I am at the chicken and the egg -
Maybe someone has a better way to do this?
I like to have 2 lines (rows) in datagrid, which is together. So normally in a grid you have 1 line per row and every next line/row is independent... But I like to have 2 lines. e.g. 1st row the name,address and 2nd line some amounts, or dates.... so every 2 line is together..
what control do I need to use in Winforms to achieve this... I'm newbie, so I prefer simple solution...
e.g. below I like to use (amount fields should be shown on next line in Datagrid)
DocNumber DocType DueDate SupplierNo SupplierName
Amount VATAmount Total Amount
10000 SA 01-05-2012 1025 Supplier-A
12.25 0.25 12.25
10001 SA 12-12-2014 1095 Supplier-B
42.25 5.25 47.00
10002 SB 31-11-2012 1099 Supplier-C
152.25 55.25 192.00
You could add an extra column to your data (i.e DataTable, for instance) where you specify the row order, and then hide it in your control (a DataGridView for instance).
However this has several drawbacks the first one that comes to mind is that if you click on column headers to sort the grid contents, it will not preserve the order of your rows.
Hope this helps.
Well sounds like to me you need to "group" your data if that's what I'm reading right.
However if this is the case I'm afraid Winforms DGVs do not support this as default as far as my understanding is.
I found this link but havent tried it, looks to be a possible work around/hack for it.
Group Functionality for Winforms Datagridviews
On the plus side there are alot of 3rd party options such as:
Telerik Controls
Or my Personnel favorite :
DevExpress Controls
Beware though even though u can do trials, You may have to pay for publishing, but worth a look!
Hope this helps!
I have a editable nested repeater containing the data.I use it for showing the data and also for saving the data which is updated by the user.
I want to detect particular cell/row for which the data has been modified by the user so that I can update only that particular row in the database instead of saving all the data again.
Is there a way to work this out.Which would be the best technique to use ,Javascript or server side code ?
Resource country etc | Week1 Week2 Week3 | Total
ABC XYZ 10 15 20 45
This is the repeater structure.
Middle one (Weeks showing hours worked by resource which is editable) is the nested repeater.
Values can only be changed in the nested repeater.
I maintain unique ID's for each resource in the hidden field.
Can you suggest me some ways to achieve this functionlity ?
This is normally handled by your ORM, but you can implement it yourself if you like. The idea is called 'change tracking', and basically what's commonly done is to retrieve the record from the database, then compare known retrieve values to the new values before saving it again.
Depending on your concurrency strategy, you also might use a hash of the original values that were sent to the client, placed in a hidden field perhaps, which you can then check original vs. currently in the database in order to not accidentally overwrite someone else's changes.
I am developing application in C# Windows Forms, i make crystal reports on the basis of data collection list in c#, for example i have a table having EmpID, Name, Sponsor, Job Title, Nationality etc. I bring them in collection in c# and pass it to crystal report, where i see my attributes in Database fields, if i drag and drop those fields on the report, for example Name, Job Title, Nationality, then i can see their columns coming in Details section, but the issue is, i have about 25 attributes and i have made a check list of 25 attributes in c#, if i check 13 attributes, it should make a report of 13 columns, the problem is, we make report in crystal report on the basis of drag and dropping fields, how can i dynamically do this, means if there are 13 fields selected in c# check list, there should be just 13 columns in report. Please find the image attached, "How currently i am doing" Please zoom it by right click on it, and open in new window.
I think that the easiest way to approach this, considering data type representations and all of the Crystal complexity under the covers, is to layout your report with all 25 fields sized appropriately.
Then, at runtime, you will need to reposition the report objects, which could be a little tricky due to the relatively unstructured way in which crystal provides the information.
The way I would approach this is to loop through the report objects and generate one SortedList for the data fields and one SortedList for the header fields. They should be sorted on their Left position so that you can process them in appearance order.
Once you have the sorted lists of objects, you can cycle through each one and, if it was not selected by the user, set the Width to 0.
As you are moving through the fields, you will keep track of the current left position. The first field that you process will set your starting point, even if it is not visible. Then, for all subsequent fields, if the field is visible, you will set its left value to the current left position, then add its width plus some separator space to the current left position for the next field.
Hopefully this will help you solve your problem.
It sounds like this would be a good place for a cross-tab report. In this case you'd need to add a cross tab to your report header or footer and pass your data into the report with a column for each attribute descriptions and then group on the attribute description. See below for details:
Data:
RowID ColDesc ColValue
1 Attr1 Value1
1 Attr2 Value2
2 Attr1 Value3
Then you can add your crosstab where your row field is RowID, your column field is ColDesc and the field to summarize is ColValue. You can use a Max of summary on the summarized field since it is different.
This is untested, but I believe that the output for this should be:
CrossTab:
Attr1 Attr2
1 Value1 Value2
2 Value3
As you can see that as you add a new attribute it will show up as a new column in the crosstab. As I said previously, this is untested so I apologize for any errors, but I hope it is enough to help you out. Thanks
Give a look at these links
http://www.c-sharpcorner.com/UploadFile/uditsingh/CR1111022006055359AM/CR11.aspx
http://www.crystalkeen.com/articles/crystalreports/dynamiccrosstab.htm
Using this Google Search
Crystal Reports will not automatically add columns & headers to a report given a list of fields.
My recommendation is to use the Report Application Server .NET SDK to dynamically alter a report. The link includes the API reference, as well as samples.