|
Key concepts: Reflection and public properties. What you're attempting is the same concept that .Net uses in data binding; i.e. string property "names" that are resolved at binding time. Getting back to your situation, consider this:
using System;
using System.Reflection;
namespace ConsoleApplication1 {
class Program {
static void Main( string[] args ) {
Person aPerson = new Person() { FirstName = "Phil", Age = 39 };
string propertyName = "FirstName";
PropertyInfo personProperty =
aPerson.GetType().GetProperty( propertyName );
// Displays: FirstName = Phil
Console.WriteLine( "{0} = {1}",
propertyName, personProperty.GetValue( aPerson, null ) );
}
}
public class Person {
public string FirstName { get; set; }
public int Age { get; set; }
}
}
|
|
|
|
|
In addition, use "SetValue" instead of "GetValue" to assign a value to your "named" properties.
|
|
|
|
|
Hello!
My intention is to write a program in C# that creates a database in SqlServer 2005.
For that reason I use SqlServer 2005. In a specific directory I have serveral Sql Script written in TSQL that creates tables and stored procedures. As I can see in debug mode in Visual Studio 2008 all characters in theese files is read correctly.
I'm from sweden so we have our specific character Å, Ä and Ö.
When I have read the TSQL script into a variable I want to execute the ExecuteNOnQuery(script) method in the smo API. My table will now be created in the database but the character Å, Ä and Ö is missing!!!
I wan't a solution for this problem quickly!
Maybe somebody has experience of smo, sqlserver and C#.
Best regards
|
|
|
|
|
Håkan Axheim wrote: I wan't a solution for this problem quickly!
*grin* of course you do.
Is your database set up to have a character set that includes those characters ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Yes our database is correct installed so this character set will be supported.
|
|
|
|
|
When I press a button (soft key on touch screen, or key on mobile device) I want to disable all other events from other buttons for a certain time. For example when I press Button1, I want Button1, events to be ignored for a few seconds, and then be active again. I have tried Button1.Enabled = false; if I press Button1 while it is disabled, when I re-enable it, the events still occur.
private void Button1_Click(object sender, EventArgs e)
{
Button1.Enabled = false;
textBox1.Text = "Button1 Pressed";
Thread.Sleep(Time);
Button1.Enabled = true;
}
How can I keep these events from occurring while the button is disabled?
|
|
|
|
|
I'd imagine you need a timer and a flag which is checked inside all the other events.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Sorry, I'm new to C# so please forgive the ignorance...
I have a list, and want to make another list from the first list:
int[] list1 = { 1, 3, 5, 7, 9 };
int[,] list2;
for (int i = 0; i < list1.Length; i++)
{
list2[i] = [item from list1] , [i];
}
How do i put items in list2? I'm looking for:
{{1,0} {3,2} {5,3} {7,4} {9,5}}
Thank you for your time.
|
|
|
|
|
What are you really looking for? Your example does not make sense to me.
|
|
|
|
|
I have this list:
int[] list1 = { 1, 3, 5, 7, 9 };
Using 'for', how do I create the following list using the first list?
{{1,0} {3,2} {5,3} {7,4} {9,5}}
Thanks.
|
|
|
|
|
The second elements of the sub-array's in your second array does not make enough sense and does not match your description.
{{1,0} {3,1} {5,2} {7,3} {9,4}} would make sense and match your description.
|
|
|
|
|
I'm sorry all, my example was poor. Yes, this is what is needed.
I can't figure out the syntax needed inside 'for'. Could you help me please?
|
|
|
|
|
warning: untested
int[] list1 = { 1, 3, 5, 7, 9 };
int[,] list2 = new int[5,2];
for (int i = 0; i < list1.Length; i++)
{
list2[i, 0] = list1[i];
list2[i, 1] = i;
}
|
|
|
|
|
Thank you. I wasn't even close & wasn't aware of 'code block' which scrambled my example.
Thanks again for your patience.
|
|
|
|
|
|
int[,] gives you a two dimensional list, not a list of pairs of numbers.
int[3,3] gives you a grid of 9 values, all of them a single int. To store pairs you'd need to define a struct, or you could use a map if you wanted ( which pairs values and lets you look up one value based on the other instead of an index ). I suspect that you're just experimenting, b/c I can't see any use for your final example ( the second value is always the same as the array index, so you have access to that number all the time anyhow ). Imagine I had a tic tac toe board for a game:
| |
___________
| |
___________
| |
Now - I can create a grid that's 3x3 with List[3,3] and I can use co-ordinates to look up positions in that list and track the game positions. That's the sort of thing a 2D array is used for.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Thank you.
I want to get:
{{1,0} {3,2} {5,3} {7,4} {9,5}}
from an original list of:
int [] list1 = { 1, 3, 5, 7, 9 };
using the increment in 'for' as the second number
|
|
|
|
|
Then you need to define a struct that contains those two numbers and build a list of them.
struct myStruct
{
public int value;
public int index;
}
will work just fine. Of course then you need to write your own code if you want to search or sort the list.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I have a datalist with an embedded dropdownlist. How can I fire an event from the dropdownlist and caclulate the results for a label in the datalist?
The datalist is similar to a shopping cart. The fore mentioned dropdownlist is the qty for each item. The total price is calculted using the qty and another field "PriceEach".
Most of the data is retrieved from a sql stored produre.
I wrote the following Item_Bound function to set the totalprice at the page_load.
protected void Item_Bound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddlist = (DropDownList)e.Item.FindControl("ddlQty");
Label TotPrice = (Label)e.Item.FindControl("lblTotalPrice");
Label PriceEA = (Label)e.Item.FindControl("lblPrice");
if (PriceEA.Text != null && PriceEA.Text.ToString() != "")
{
string price = PriceEA.Text.Replace("$", "");
Double dblPrice = Convert.ToDouble(price);
Double ProdQty = Convert.ToDouble(ddlist.SelectedValue.ToString());
Double ExtPrice = (dblPrice * ProdQty);
TotPrice.Text = ExtPrice.ToString();
}
}
}
|
|
|
|
|
Then what is the error you are getting... The code looks fine to me.
|
|
|
|
|
I'm trying to add code to get the qty when it is changed. I added an event to the Dropdownlist "ddlQty" called OnSelectedIndexChanged="ddlQty_Changed" and started to add the following:
protected void ddlQty_Changed(object sender, DataListItemEventArgs e)
{
DropDownList ddQty = (DropDownList)e.Item.FindControl("ddlQty");
if (ddQty.SelectedValue != null && ddQty.SelectedValue.ToString() != "")
{
Double ProdQty = Convert.ToDouble(ddQty.SelectedValue.ToString());
}
}
When I run this I get the error: No overload for 'ddlQty_Changed' matches delegate 'System.EventHandler'
|
|
|
|
|
I think the signature of ddlQty_Changed should be
protected void ddlQty_Changed(object sender, EventArgs e)
|
|
|
|
|
When I try that I can't find the "e.item" in:
DropDownList ddQty = (DropDownList)e.Item.FindControl("ddlQty");
Fixed it:
protected void ddlQty_Changed(object sender, EventArgs e)
{
foreach (DataListItem item in DataList1.Items)
{
Label TotPrice = (Label)item.FindControl("lblTotalPrice");
Label PriceEA = (Label)item.FindControl("lblPrice");
DropDownList ddlist = (DropDownList)item.FindControl("ddlQty");
if (ddlist.SelectedValue != null && ddlist.SelectedValue.ToString() != "")
{
string price = PriceEA.Text.Replace("$", "");
Double dblPrice = Convert.ToDouble(price);
Double ProdQty = Convert.ToDouble(ddlist.SelectedValue.ToString());
Double ExtPrice = (dblPrice * ProdQty);
TotPrice.Text = String.Format("${0 ,0}", ExtPrice.ToString());
}
}
}
Thanks for all the help
modified on Tuesday, November 10, 2009 3:55 PM
|
|
|
|
|
Thats nice.
|
|
|
|
|
Hello,
The question is simple but I found it tricky to accomplish.
I want to extract all the text from within the default.code node:
< default.code >
<script type="text/javascript"><!--
google_ad_client = "<?php echo($adsense_pubid);?>";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "image";
google_ad_channel = "";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "245917";
google_color_text = "555555";
google_color_url = "555555";
google_ui_features = "rc:6";
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
< /default.code >
The problem is that when I read it, the is also considered a XML node. I simply want to extract the javascript code block.
How can I do this ?
Thanks
|
|
|
|