|
You can handle that as below:
if (dr["fieldname"] != null)
{
//do something
}
|
|
|
|
|
|
I have tree view control on my asp.net web page.
this tree control has check boxes on every node.
I want when user selects or make parent node check box checked then its child should also get checked automatically.
how can i do this ?
kindly its urgent, plz send some code hints.
|
|
|
|
|
Write some fancy javascript to update all the sub nodes that contain a checkbox, or put the treeview in an ajax panel and use server side code to check all the checkboxes.
I didn't get any requirements for the signature
|
|
|
|
|
we r using asp.net and we have also created check boxes, we want parent node check box checked then its child should also get checked automatically.
|
|
|
|
|
enumerate though the childnodes and check the checkboxes.
Post your code so you can get further help.
|
|
|
|
|
heres the code
public partial class _Default : System.Web.UI.Page
{
public static SqlConnection sqlConn = new SqlConnection();
public static SqlCommand sqlCmmd = new SqlCommand();
public static SqlDataAdapter sqlDAptr = new SqlDataAdapter();
protected void Page_Load(object sender, EventArgs e)
{
try
{
PassQuery();
}
catch (Exception)
{
throw;
}
}
public void PassQuery()
{
this.TreeView1.Nodes.Clear();
DataSet myFirstTable = new DataSet();
string Query = "select name from sys.tables";
myFirstTable = Retun_Table_BasedOn_Query(Query);
DataSet[] mySecondTable = new DataSet[myFirstTable.Tables[0].Rows.Count];
for (int i = 0; i < myFirstTable.Tables["Table"].Rows.Count; i++)
{
string str1 = myFirstTable.Tables["Table"].Rows[i][0].ToString();
string Query2 = "SELECT sysobjects.name As Names, syscolumns.name AS FieldName " +
"FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id " +
"WHERE (sysobjects.name = '" + str1 + "')";
mySecondTable[i] = Retun_Table_BasedOn_Query(Query2);
TreeNode tnParent;
TreeNode tnChild;
for (int a = 0; a < 1; a++)
{
tnParent = new TreeNode();
tnParent.Text = str1.ToString();
TreeView1.Nodes.Add(tnParent);
foreach (DataRow rowChild in mySecondTable[i].Tables["Table"].Rows)
{
tnChild = new TreeNode();
tnChild.Text = rowChild["FieldName"].ToString();
tnParent.ChildNodes.Add(tnChild);
}
}
}
}
public void Open_Connection()
{
string Conn_Str = "Data Source=dev-test;Initial Catalog=Malik;Persist Security Info=True;User ID=interns;Password=intern123";
sqlConn = new SqlConnection(Conn_Str);
if (sqlConn.State != ConnectionState.Open)
{
sqlConn.Open();
}
}
public DataSet Retun_Table_BasedOn_Query(String Query)
{
Open_Connection();
DataSet mydataSet = new DataSet();
sqlCmmd = new SqlCommand(Query, sqlConn);
sqlDAptr = new SqlDataAdapter(sqlCmmd);
sqlDAptr.Fill(mydataSet);
return mydataSet;
}
}
help
|
|
|
|
|
T_Teef wrote:
Open_Connection();
DataSet mydataSet = new DataSet();
sqlCmmd = new SqlCommand(Query, sqlConn);
sqlDAptr = new SqlDataAdapter(sqlCmmd);
sqlDAptr.Fill(mydataSet);
return mydataSet;
FYI. If you pass an open connection to a SqlDataAdapter it will not close automatically. Check your sql server you probably have a bunch open connections that aren't being closed.
Also, where is your code to handle the treeviews click event?
I didn't get any requirements for the signature
|
|
|
|
|
thats why we have posted the code to get the help to obtain a piece of code to handle the treeviews click event
|
|
|
|
|
hello,
i want to add a "hello ___" to all my pages.
now , in order not to duplicate code , i can put it in the master page.
in the master page i go and look for the user entered from the query string at the DB and put the name after the hello or Guest if i get null.
this works fine.
now, in the child pages i also want to use this DB output , so i use session to store the DB entry for later use by the child.
my problem is that the child page's On_Load is performed prior to the Master page's On_Load and this causes the DB entry to be null before it was read by the Master page.
does anyone have any idea how to solve this problem ?
can i use the Page_Init in the master page for this ? is it acceptable and stable ?
tnx,
avi
modified on Wednesday, April 22, 2009 3:54 PM
|
|
|
|
|
Use the Mater Page's Page_Init event to run the code. That event fires before the child pages load event.
I didn't get any requirements for the signature
|
|
|
|
|
ok , tnx
|
|
|
|
|
How do I store a custom object in a ViewState. I know that viewstates do not support XmlSerialization. I currently have a class that is using XmlSerialization and all hell is breaking lose when trying to set a viewstate entry to that value.
|
|
|
|
|
ViewState is actually a name / value collection. You can't store a class in ViewState.
You can store a serializable object in Session though.
I didn't get any requirements for the signature
|
|
|
|
|
You can store an object inside a viewstate as long as it is BinaryFormat-able.
|
|
|
|
|
So is that what you are doing?
In my 8 years of doing asp.net I have never once tried to store an object in viewstate. Can ask why you want to store an object in viewstate?
I didn't get any requirements for the signature
|
|
|
|
|
I am trying to store the object in a control. What do you suggest?
|
|
|
|
|
Well, if you have a base page class or a master page. Store the object in session.
The reason for the base page class or master page is that you can check what aspx page is being loaded and set the session object to null if it is no longer needed. So it will behave like viewstate but you won't have all that data traveling back and forth to the client.
I didn't get any requirements for the signature
|
|
|
|
|
In the absence of a master page or base class you can also use the global.asax to manage the session objects.
|
|
|
|
|
Thanks for the tip, I never thought of that. Does the Application_BeginRequest event fire on every post back?
I didn't get any requirements for the signature
|
|
|
|
|
I think so but the way I usually do it is to wire up an event to page PreInit in Application_PreRequestHandlerExecute. It might not be the best way to do it (so I'm open to suggestions) but it works a treat.
|
|
|
|
|
I wanted to avoid using session vars, but I guess that is my only option at the moment. Thanks!
|
|
|
|
|
Just one more tip for you.
Create a static class to hold all your session objects. For example
public static class SessionItems
{
public static YourObjectType YourObject
{
get
{
Object result = HttpContext.Current.Session["YourObject"];
if (result == null)
return null;
else
return (YourObjectType)result;
}
set { HttpContext.Current.Session["YourObject"] = value; }
}
}
It makes it easier to manager your session objects this way, plus it prevents bugs from trying to access a session object that does not exist. Also prevents bugs that can occur from mispellings
I didn't get any requirements for the signature
|
|
|
|
|
Dear All,
I have a requirement that i want to send mail to all my user registered on my site in last 24 hours.
Manually its working fine but i dont want that a operator has to sit and search data then click on some button to send the mail. I want that by using some automated process that server automattically send the mail at the desire time.
Plz do reply what could be the possible conditions.
Thanks and Regards
|
|
|
|
|
Create an application that reads your database of registered users, selecting those users that have registered on the current day and generate your email. Sounds pretty straight forward, right ?
Are you familiar with a programming language such as VB.net or C#.net ?
Are you capturing the registered user with a date stamp of when they registered ?
Once the application is written, you could simply schedule it to run each night at 23:59 (just before midnight) to generate the emails.
|
|
|
|