|
See this example :
using System;
using System.IO;
using System.Xml.Serialization;
namespace ConsoleApplication10
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
SerializeToXML();
DeserializeFromXML();
}
static void SerializeToXML()
{
XmlSerializer xs = new XmlSerializer(typeof(MyDataClass));
MyDataClass mdc = new MyDataClass();
mdc.A = 10;
mdc.S = "Hello World";
mdc.D = new double[3];
mdc.D[0] = 0.456;
mdc.D[1] = 1.234;
mdc.D[2] = 4.234;
Stream writer = new FileStream("test.xml", FileMode.Create);
xs.Serialize(writer, mdc);
writer.Close();
}
static void DeserializeFromXML()
{
XmlSerializer xs = new XmlSerializer(typeof(MyDataClass));
Stream reader= new FileStream("test.xml",FileMode.Open);
MyDataClass mdc = (MyDataClass) xs.Deserialize(reader);
Console.WriteLine(mdc.A);
Console.WriteLine(mdc.S);
for(int i = 0; i < mdc.D.Length; i++)
{
Console.WriteLine(mdc.D[i]);
}
}
}
public class MyDataClass
{
private int a = 0;
private string s = "";
private double[] d = null;
public int A
{
get { return this.a; }
set { this.a = value; }
}
public string S
{
get { return this.s; }
set { this.s = value; }
}
public double[] D
{
get { return this.d; }
set { this.d = value; }
}
}
}
|
|
|
|
|
thxx sir i ll use this code
Regards,
|
|
|
|
|
hi all,i have a checkbox in header template of the grid i don't know how to find that checkbox is checked or not.anybody can help me to solve this problem?pls......
ayyp
|
|
|
|
|
Hi,
In OnDataItemBound event you can find that control after checking for the Itemtype.
Best Regards,
Apurva Kaushal
|
|
|
|
|
i didn't get u, can u say in detail
ayyp
|
|
|
|
|
Hi,
OnItemDataBound event you can first check for the itemtype if it is a header then you can find the control inside that. Something like this:
if(e.Item.ItemType==ListItemType.Header)
{<br />
CheckBox chk = (CheckBox)e.Item.FindControl("kaus");<br />
chk.Checked=true;<br />
}
Hope this will help.
Best Regards,
Apurva Kaushal
|
|
|
|
|
k thanks
ayyp
|
|
|
|
|
Best Regards,
Apurva Kaushal
|
|
|
|
|
hi apurva,i tryed as u told but it will find that checkbox only when the page is loading,when datagrid.bind() method is called the control return to onitemdatabound but it says the checkbox is not checked(but i checked it)what to do is there any mistake with me?
ayyp
|
|
|
|
|
Hi,
I dont know whats wrong there because here it is working fine. When are you making that checkbox checked because as you told.
ayyp wrote: checkbox is not checked
Here first the onitemcreate will fire and then OnItemBound will fire.
Best Regards,
Apurva Kaushal
|
|
|
|
|
hai apurva this is the code i written
private void DataGrid2_ItemDataBound(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Header)
{
CheckBox chk=(CheckBox) e.Item.FindControl("CheckBox1");
if(chk.Checked==true)
Response.Write("true");
else
Response.Write("false");
}
}
when the page is loading it display false ofcourse that was true (because initially the checkbox is not checked), but after checking checkbox and click on any button on the page it display as false .whats wrong with this code ,if it possible then snd the correct code...plz....
ayyp
|
|
|
|
|
Hi ayyp,
I have done the same thing and when the page is loading after the postback i am getting the checkbox as checked unlike you. One thing is there where you are binding the datagrid, if it is in page load then put that code when the page is not postback otherwise it will get executed everytime the page is posted back.
Like this:
if(!Page.IsPostBack)
{
//You code goes here.
}
Hope this will help you.
Best Regards,
Apurva Kaushal
|
|
|
|
|
hai apurva, really i don't what wrong with my code here is my entire page code.check this plz........
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
bind();
}
}
public void bind()
{
con.Open();
SqlCommand cmd=new SqlCommand("select * from grid",con);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds);
DataGrid2.DataSource=ds;
DataGrid2.DataBind();
con.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
bind();
}
private void DataGrid2_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Header)
{
CheckBox chk=(CheckBox) e.Item.FindControl("CheckBox1");
if(chk.Checked==true)
Response.Write("true");
else
Response.Write("false");
}
}
if possible plz snd u r code....that will help me
and here i find one more thing when i click on the button the checkbox is automatically turned to unchecked thats why it display false is this any reason for this?why it happening like this?
ayyp
-- modified at 1:57 Wednesday 24th May, 2006
|
|
|
|
|
Hi,
Actually you are binding the datagrid in the button click event and because of that the complete datagrid is loaded again(fresh one). That is why if you are checking then also it is getting unchecked.
Best Regards,
Apurva Kaushal
|
|
|
|
|
hi Friend
I want Share Folder in mycomputer by C#
some friend help me!!
|
|
|
|
|
|
hi,
i'm writing application that extends "Active Directory Users and Computers" snap-in capabilities, but i'm stuck on how to get icons for AD objects. I found that there is a dll "dsuiext.dll" with some AD icons, but maybe is other way how to get these icons for specific type of object. In MSDN i found method "The IDsDisplaySpecifier::GetIcon method obtains the icon for a given object class" but i didn't get how to use it.
Maybe there is someone who has experience with it? Thanks for help
|
|
|
|
|
Lors de la saisie d'un nombre décimal dans un textBox numérique, comment faire pour que le point qui se trouve sur le pavé numérique du clavier soit utilisé comme une virgule?
|
|
|
|
|
Hi,
Please use English.
Best Regards,
Apurva Kaushal
|
|
|
|
|
He sais (thank you google translate):
During the seizure of a decimal number in a numerical textBox, how to make so that the point which is on the numeric keypad of the keyboard is used like a comma?
Answer:
string test = txtBox.Text;
test.Replace( ",", "." );
long number = Convert.ToInt64( test );
|
|
|
|
|
Thanks.
Best Regards,
Apurva Kaushal
|
|
|
|
|
My problem is that when i press on the point which is on the numeric keypad nothing appears? I would like to use that point instead of that one which is usually used (on the left keypad).
Thanks!
|
|
|
|
|
I think this is a problem in your settings, not in your program. Do you get a comma or a point when you press that button in notepad.exe ?
|
|
|
|
|
|
That is kind of a weird situation you have their! I'm running out of solutions i'm afraid.
|
|
|
|