|
Also, please check Readup on SQL Injection.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Oh well, It was my mistake. I may blind! It must be SqlDataReader in fact!
Thanks again!
Chuon Visoth
Angkor Wat - Cambodia
asp.net - c sharp beginner
|
|
|
|
|
I'm wondering, how would I go about doing this in a much easier and logical manner? I have a lot of checkBox's being used and each one needs this exactly type of coding, just each one consecutively needs to have their object number +1 as shown below.
object cb1 = checkBox1.Tag;
object cb2 = checkBox2.Tag;
object cb3 = checkBox3.Tag;
if (checkBox2.Checked == true)
{
cb2 = "1";
}
else
{
cb2 = "0";
}
if (checkBox3.Checked == true)
{
cb3 = "1";
}
else
{
cb3 = "0";
}
if (checkBox1.Checked == true)
{
cb1 = "1";
}
else
{
cb1 = "0";
}
Help would be greatly appreciated!
|
|
|
|
|
Hi,
this does not make much sense to me. What is the use of storing the checked state in a string which is inside the Tag property, when the Checked state is already available as a boolean?
Anyway, this probably is what you asked for:
foreach(Control c in Controls) {
CheckBox cb=c as CheckBox;
if (cb!=null) cb.Tag=cb.Checked?"1":"0";
}
works whatever the number of checkboxes is, as long as they are all present in this.Controls
(if they are nested in panels, groupboxes, whatever, you may need some recursion).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I suspect you are trying to be able to have a property with a 1 or 0 rather than a true or false (i.e. you dont ACTUALLY want to use Tag with a string, you are just using that as it is convenient)
If that's the case, why not make your own Checkbox:
using System.Windows.Forms;
namespace SomeNamespaceOrOther
{
public class MyCheckBox : CheckBox
{
public int TrueFalseValue
{
get
{
return Checked ? 1 : 0;
}
}
}
}
Then use it like your normalk checkbox, but access the TrueFalseValue property rather than the Tag or Checked property.
You can give it a 'setter' if you want - so setting the property to, say, 0 will make the checkbox unchecked.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Can I use VStudio to design sleek looking windows applications, something like Google Chrome. If yes how?
|
|
|
|
|
Yeah you can, UI's can be tricky to design, but there is no reason why not if you put in enough effort.
humayunlalzad wrote: If yes how?
By coding.
|
|
|
|
|
You might want to use WPF if you want 'prettyness'
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
|
suppose I have 3 functions.
1.
[CustomAttrib("First")]
public int Foo1(ref int x, out float y, SomeDelegate callback)
2.
[CustomAttrib("Second")]
public Stream Foo2(string name, SomeEnum enums);
3.
[CustomAttrib("Third')]
public void Foo3(string message, out double count, SomeStruct str);
Now what I want to do, is to validate each function according to their attribute. I want to create only one function named Validate which will validate all the above functions and then call them.
I tried to use delegate, lambda expression in Validate to pass the function, but nothing can get the attribute data.
I already tried :
public object Validate(Func<object> method) { .... } and call it as
Validate(() => Foo1(ref x, out y, DoCallBack));
or
public object Validate(Delegate method) { .... } & call it as
Validate(delegate() {return Foo2(null, SomeEnum.EnumValue); };
but none of them can get the attribute information of the called function
[Foo1, Foo2 etc.] in the body of Validate function.
Can anybody please suggest me any way-around to accomplish this task?
modified on Friday, May 22, 2009 12:32 AM
|
|
|
|
|
Hello,
I have datagrid in my application.
I want to create event that will be raised when datagrid columns were reordered by user (and then do something).
how can i do it?
|
|
|
|
|
Hi,
look for ColumnReordering and ColumnReordered events.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
there is no such event in events list of the datagrid.
What i want to do is after the user reorderes the columns (drag-drop column) the index of the moved column and the other will be changed according their new position. If i won't change the index- their index will be remaind as before even if the real position of the column is not as shown...
|
|
|
|
|
Sorry, WPF has it, WinForms does not.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi
I am trying to POST some data to a webpage by using HttpWebRequest. But the webpage tells me that my security level is too high and I should check my browser settings.
How can I solve this? It is really urgent.
My code (if you need it):
Uri adres = new Uri("http://*********/****.asp");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(adres);
request.Method = "POST";
request.CookieContainer = new CookieContainer ();
request.CookieContainer.SetCookies(adres, webBrowser1.Document.Cookie);
string postData = "*********************";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream ();
dataStream.Write (byteArray, 0, byteArray.Length);
dataStream.Close ();
WebResponse response = request.GetResponse ();
dataStream = response.GetResponseStream ();
StreamReader reader = new StreamReader (dataStream);
string responseFromServer = reader.ReadToEnd ();
StreamWriter sr = new StreamWriter(@"C:\Users\Admin\Desktop\response.html");
sr.Write(responseFromServer);
sr.Close();
sr.Dispose();
reader.Close ();
dataStream.Close ();
response.Close ();
Thanks in advance.
|
|
|
|
|
SimpleData wrote: It is really urgent
So?
SimpleData wrote: request.CookieContainer.SetCookies(adres, webBrowser1.Document.Cookie);
With the high IE security setting, you app can not create cookies.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
My IE is not set to high security.
|
|
|
|
|
my code is here . what is the misstake ? it error when click on that button and message that "the object reference not set to an instand of an object". please give me some help
void Button_Click(object sender, EventArgs e)
{
Button clickedButton = sender as Button ;
if (clickedButton.Name == "Program")
{
MessageBox.Show("lkjd;lfjal;sdkjf;laksdjfl;jasd");
}
else
{
MessageBox.Show("dddddddddddddddd");
}
}
modified on Thursday, May 21, 2009 3:27 PM
|
|
|
|
|
Hi,
if that handler gets connected to an event of something other than a Button, then
Button clickedButton = sender as Button ; will set clickedButton to null.
You can take care of that by changing your code to:
...
if (clickedButton!=null && clickedButton.Name == "Program")
...
or by making absolutely sure only Buttons are being wired up to this handler.
FWIW: the fact that the handler's name starts with "Button" is fine for readability but does not change the way the code works.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Are you sure the Button you are clicking on is a Button (and not some other control).
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
my code is like bellow. but i don know the reason why it error? it message "Cannot assign to 'mnuItem' because it is a method group". please help me......
public DataTable mnuItem()
{
DataConnection dc = new DataConnection();
SqlConnection Cn = new SqlConnection(dc.ConnectStr);
SqlDataAdapter Da = new SqlDataAdapter();
DataSet Ds = new DataSet ();
DataTable Dt = new DataTable();
Cn.Open ();
SqlCommand Cmd = new SqlCommand("select ObjectID, ObjectName from _Objects where ObjectType='MENU' ", Cn);
Da.SelectCommand = Cmd;
Da.Fill(Ds, "_Objects");
Dt = Ds.Tables["_Objects"];
Da.Dispose();
Cn.Close();
mnuItem = Dt;
return mnuItem ;
}
|
|
|
|
|
You are assigning the function mnuItem the value of a DataTable. This would have worked in VB, but in C# you just need to use return Dt; . Incidentally, 'return mnuItem' would generate a StackOverflowException and a syntax error. Remove it
|
|
|
|
|
Additionally, the following line is pointless:
xingselex wrote: DataTable Dt = new DataTable();
Since you assign it later on to:
xingselex wrote: Dt = Ds.Tables["_Objects"];
This means you're creating an instance of a DataTable that is then discarded without use. Instead just declare it, or explicitly assign to null:
DataTable Dt;
or
DataTable Dt = null;
10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011
|
|
|
|
|
I think u just remove the last 2 lines. Then after Cn.Close(); write return Dt;
|
|
|
|
|
Hello.
I have a application, that does automative navigating of a webbrowser object..
I just often get the error:
"object reference not set to an instance of an object"
when the application is trying to get the html source or the lenght of a site, with this code:
if (webBrowser1.Document.Window.Frames[2].Document.Body.InnerHtml.Length < 5)
{
return true;
}
Even though I have functions that waits for the site to load done before continue it often occurs if the internet are a bit slow..
Is there anyway I can check if the object reference is set, or another way to solve this?
Hope there is help to find
|
|
|
|