|
hi
just use the process class and pass the args
|
|
|
|
|
Hi, im making a dynamic site in ASP.NET and coding in C#. And I have a problem. The system is kind of like a windows desktop where you can drag around windows etc etc, but now i want to run a function to add something to the database. And this is fine, using a asp button and using its onclick function. BUT that causes a postback which refreshes the windows back to their original places and resets everything back to how it started. So im thinking the best plan would be to just use an HTML button and run the C# function from JS. But I have no clue how to do that. Or even if thats what I should be doing.
Thanks so much,
Matt
|
|
|
|
|
In order to do this without a postback you really want to consider using AJAX.
|
|
|
|
|
You could probably implement the ICallbackEventHandler interface. The MSDN sample is clear enough. I tried it successfully last week. I used to write a simple page that generated random numbers on the server. I had a loop in javascript that would retrieve the latest number and update a label on the page on the client side.
Here's a link to the MSDN article I used as a guide:
Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages[^]
|
|
|
|
|
The code I have below only takes data from one dynamically created tabpage (the default)‘s datagrid and exports it to a spreadsheet. I would like the application to take the data from all the dynamically created tabpages’ datagrids and export the data to excel and create a new worksheet for each tabpage as it is exporting. Please help.
Microsoft.Office.Interop.Excel._Application _appClass = new ApplicationClass();
_appClass.Visible = true;
_appClass.Caption = "Exported ECS Errors";
Microsoft.Office.Interop.Excel.Workbook wbk = _appClass.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet obj = (Worksheet)wbk.ActiveSheet;
// get the collection of sheets in the workbook
Microsoft.Office.Interop.Excel.Sheets sheets = wbk.Worksheets;
Range r = (Range)obj.Cells;
try
{
//Load the Headers and make them BOLD
for (int i = 0; i < ((DataGridView)this.dgOutput).Columns.Count; i++)
{
r[1, i + 1] = ((DataGridView)this.dgOutput).Columns[i].HeaderText.ToString();
((Range)r.Cells[1, i + 1]).Font.Bold = true;
}
//Load the data from the datagrid to the new spreadsheet
for (int i = 1; i < ((DataGridView)this.dgOutput).Rows.Count - 1; i++)
{
for (int j = 0; j < ((DataGridView)this.dgOutput).Columns.Count; j++)
{
r[i + 1, j + 1] = ((DataGridView)this.dgOutput).Rows[i].Cells[j].Value.ToString();
//Do the colors
if (((DataGridView)this.dgOutput).Rows[i].Cells[j].Value.ToString() == "Update OK")
{
((Range)r.Cells[i + 1, 1]).Font.Color = Color.Green.G;
}
}
}
}
catch (Exception EX) //user closes the Excel file while it is loading data from the datagrid
{
MessageBox.Show(EX.Message + "The Excel file was closed while loading data from the datagrid.",
"Error : Loading file!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Mvelo Walaza
Developer
Telkom SA
|
|
|
|
|
hy everyone!
i do have a problem, sounds easy but i didn't find a solution so far.
i have a textfile which contains fieldnames like |pagenumber|
i want to replace this fieldname with the number of the page. this could be of length 1, 2, 3 ...
everything works fine until the switch from length 1 to length 2, length 2 to length 3 etc.
I want it to look like
my town
1
......
my town
9
my town
10
.....
my town
100
buy it looks like
my town
1
.....
my town
9
my town
10
even if i move it to the left then the first few numbers are too far to the left.
does anyone of you know a way how to replace a text and format it correctly.
thanks.
stephan.
modified on Tuesday, April 8, 2008 3:48 PM
|
|
|
|
|
did you read your post?
without PRE tags it does not show any difference between what is obtained and what is wanted.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
thanks for your hint.
i just edited it.
here it is again:
should be
my town
1
......
my town
9
my town
10
.....
my town
100
but it looks like
my town
1
.....
my town
9
my town
10
i use the
string.replace(Tag, Value) function
I do have a template which symbolizes a page of the output. in there i do have fields/tags like |tagname| which have to be replaced by its value. and there is a tag called |pagenum| which should be replaced by 1 on the first page, 2 on the second one and so on.
The "template" for every page is the same, therefore I do only load page by page, because otherwise all occurances will be replaced.
i know how many pages will be in total.
so to replace the tag |pagenum| i call the function
template = template.replace(pagetag, convert.toString(pagevalue));
the pagetag is generated some lines above. the pagevalue is an integer. but no matter what i try it looks like the string which replaces the tag starts where the tag ended.
does anyone have an idea of how to realize the correct positioning of the pagenumbers?
thanks.
stephan.
|
|
|
|
|
Hi, i have a file containing integers seperated by comma's, these values could be any number, e.g. they maybe 1, they maybe 10, they maybe 100.
so i read the line in from the file, i then import integers only from the line. How do i count same integer types?
e.g. when i read line 1 it has 10 1's and 5 100's, how can i do a check to say that the line contains 10 ones and then output the value as a string?
If you need sample code which i have at the minute then let me know, otherwise i'd apprechiate if people told me what i need to do,
p.s. saying try csvparser isn't what i want, nor is saying "you need to use this third party program", it can be done with the standard built in c# librarys
thanks
|
|
|
|
|
Sharkadder wrote: p.s. saying try csvparser isn't what i want, nor is saying "you need to use this third party program", it can be done with the standard built in c# librarys
Definitely not appreciated.
String[] split = yourFile.ReadLine().Split(',');
Int32 num = split.Count;
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
sorry about that scott, i don't mean to offend, just i've been reading up on it and alot of people have said to use these third party applications, when they are not even needed. Thanks for that, i will look into it when i get home later on.
All i am looking for is to sort all my numbers out, so i could have 10 5's, 20 1's etc. and they would be displayed like this:
5 = 10, 1 = 20 etc. but i'm not sure your code gives me a full answer, i already knew the code you posted, but i will look further into it later.
Remember i wasn't after adding all the integers together, i was after counting the amount of same integer, e.g. the amount of ones i have.
thanks
|
|
|
|
|
My bad... sorry. I think the knowledge representation is the tricky part here. Once you figure out how to represent the information, the rest is a snap. Have a look, there are many ways to implement this. So I put together an example using .NET 3.5 as to what you can do. If you're using 2.0, you'll have to make the Action and Predicate delegate yourself, but it will work the same. The code will compile and run.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CountTest {
class Program {
static void Main(string[] args) {
String test = "1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9";
List<bucket> items = new List<bucket>();
String[] split = test.Split(',');
foreach (String s in split) {
Bucket b = new Bucket{ Key = s, Count = 1};
Bucket searchedBucket = items.Find(new Predicate<bucket>(bkt => b.Key.Equals(bkt.Key)));
if (searchedBucket == null) {
items.Add(b);
} else {
searchedBucket.Count++;
}
}
items.ForEach(new Action<bucket>(b => Console.WriteLine(b.ToString())));
Console.ReadLine();
}
}
public class Bucket {
public string Key;
public Int32 Count;
public override string ToString() {
return String.Format("{0} {1}{2}", Count, Key, Count > 1 ? "'s" : "");
}
}
}
</bucket></bucket></bucket></bucket>
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
If I understand your request, you're looking to count the number of occurances of each 1, 5, 10, 100, and so on, on each line or file?
Easy. Use a Dictionary, or some other Key/Value pair collection to track each item and the count for it. Off the top of my head, the core of something like this would look similar to this:
Dim itemCounts As Dictionary(Of String, Integer)
'open file and read a line here...
Dim values() As String = lineRead.Split(New Char() {","c})
For Each value As String In values
If itemCounts.ContainsKey(value) Then
' If the key is already in the collection, up the count by 1.
itemCounts(value) += 1
Else
' If the key doesn't exist yet, add the key with the count of 1.
itemCounts.Add(value, 1)
End If
Next
...
Return itemCounts
You'd treat each value as a key to the collection, whereupon each value associated with the key would be the count of the occurances of those keys.
|
|
|
|
|
thanks for the reply, what exactly do i need for this code?
e.g. system. what? Personally i have not seen code like this before, i tried putting it inside my class and everything is wrong.
I know what you posted was psudo code but i cannot figure it out. What exactly is item counts? if that the streamreader name you gave? It's abit confusing your code :S, my form won't recognise the dictionary terms or the itemcount itself. sorry about this
please can you explain more in c# terms, i have only been using the software a few months and still fuzzy on some things. thanks
modified on Tuesday, April 8, 2008 8:34 PM
|
|
|
|
|
Hi,
has anyone ever needed to report progress when (de)serializing objects? I have implemented loading/saving project files (for my application) via serialization and this could take up to 5-10 sec, depending on what's in the project. So I'd like to do it asychronously and report progress. Is there any way how to find out (de)serialization progress(perc completed)?
thanx
zilo
|
|
|
|
|
I remember reading an article about it but I can't remember where I found it. I am more than sure Google has the answer[^]
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
How do you think your post was helpful to me?
zilo
|
|
|
|
|
If my post was not helpful, you can ignore it. However, If my post was not helpful, I am afraid that none of the post will be helpful for you.
Good luck
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Thank you very much for help. Next time please don't bother me with such answers
zilo
|
|
|
|
|
Ok, I won't. If you don't want to you will not get help from me.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
That depends on how you're serializing objects. If you're just calling a single method that walks an object graph, then you're not going to get anny progress information back from that method. If you're writing the code to walk the object graph, serializing each node yourself, then you can put some extra code in there to report some kind of progress.
But, if you have no way of knowing when the end of the graph is, you really can't report any percentage of progress completed. So, you're only other option would be to use a non-progressing progress bar. It'll just show something is still happening, but not report real progress.
|
|
|
|
|
Thanx for answer.
that's what I was afraid of... I was hoping there might be at least something saying on what position of the Stream is the serializer currently, that would be more than enough for my needs...
btw I'm using BinaryFormatter.Deserialize (Serialize) and I'm implementing the ISerializable interface (GetObjectData and Constructor) for classes to serialize.
I'll just say that something is happening...
zilo
|
|
|
|
|
|
I use the function bellow to create a DataGridViewComboBoxCell in databound gridview in a datagridviewtextboxcolumn. When I enter the cell I can see the dropdown arrow, but when i click on the arrow nothing happens.
Can anybody help me please
Maris
<br />
private void AddComboBox(int index, string selectedValue, List<string> projects)<br />
{<br />
if (projects == null)<br />
throw new NullReferenceException("Project list vas empty");<br />
DataGridViewComboBoxCell aCell = new DataGridViewComboBoxCell();<br />
foreach (string s in projects)<br />
{<br />
aCell.Items.Add(s);<br />
}<br />
aCell.Value = selectedValue;<br />
aCell.DropDownWidth = 1000;<br />
_dataGridView.Rows[index].Cells[0] = aCell;<br />
}<br />
private void _dataGridView_CellMouseEnter(object sender, DataGridViewCellEventArgs e)<br />
{<br />
if (e.RowIndex >= 5 && e.RowIndex <= 9)<br />
{<br />
List<string> projectList = _domainFacade.GetProjects();<br />
string listValue = projectList[0];<br />
AddComboBox(e.RowIndex, listValue, projectList);<br />
}<br />
}<br />
|
|
|
|
|
|