Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.
You can create the SqlDataSource control in Asp.net 2.0 dynamically. Always remember to add the control to the Page control using the Controls.Add method.
 

 protected void Button1_Click(object sender, EventArgs e)
    {
        SqlDataSource s = new SqlDataSource();
        s.ID = "mySqlSourceControl";
        Page.Controls.Add(s); 
                
        s.ConnectionString = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;
        s.UpdateCommand = "UPDATE Person SET Name = @Name WHERE PersonID = 6";
        ControlParameter param = new ControlParameter();
        param.ControlID = "TextBox1";
        param.Name = "Name";
        param.PropertyName = "Text";
        s.UpdateParameters.Add(param);
        s.Update();
        
        s.DataBind(); 
        
           
    }


Posted on Tuesday, July 19, 2005 8:09 PM | Back to top


Comments on this post: Adding SqlDataSource Control programatically in Asp.net 2.0

# re: Adding SqlDataSource Control programatically in Asp.net 2.0
Requesting Gravatar...
Ultimate code,thanks alot dear
Left by Mohd hyder on Sep 07, 2006 12:26 AM

# re: Adding SqlDataSource Control programatically in Asp.net 2.0
Requesting Gravatar...
thank you sir
Left by rahul on Feb 20, 2008 11:14 PM

# re: Adding SqlDataSource Control programatically in Asp.net 2.0
Requesting Gravatar...
This code helped me greatly. Thanks!
Left by BigBison on May 01, 2008 7:42 AM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net