Archive for the ‘C# .net’ Category

Thanks to Daniel C. Douglass at ASPAlliance

Thursday, August 28th, 2008

Adapted from ASPAlliance

Thanks to Douglass who submitted this where it explains on how to access Public variables/functions of a Dynamically created User control or custom control in ASP.net c#. Apologies if this post upsets anyone in infrignes anything. Please contact me to let me know if theres a problem.

Enjoy

——————————————————–

Title: Solution to accessing properties dynamically
Name: Daniel C. Douglass
Date: 5/20/2005 12:25:31 PM
Comment:
Class name of Custom Control: New_Vote
Public Properties (in New_Vote): DirectorName, VoteID
Custom Control Filename: New.Vote.ascx

The following code should be placed in the code-behind of the web form calling the user control:

//### load user control
Control c = LoadControl(”Controls/New.Vote.ascx”);

//### cast the generic control to be voting control
New_Vote Vote = (New_Vote)c;

//### set control properties
Vote.DirectorName = “Daniel C. Douglass”;
Vote.VoteID = 117;

TitlePanel.Controls.Add(Vote);
This should help everyone!

Getting the last inserted id using datasets

Tuesday, June 17th, 2008

For heavens sake, this took me quite some time to get around. Okay here goes. 1,2,3 easy steps to get ID from MS SQL using datasets.

  1. In visual studio, under your DAL layer, you should have a dataset where you hold your table adapters.
  2. right click on the table adapter and click configure to get to your TABLEADAPTER CONFIGURATION Wizard.
  3. Click on advanced options
  4. Make sure Refresh the data Table option is checked
  5. Save the changes
  6. Go to configure your insert statement in the ADAPTER
  7. Enter a new line with — Return the applicationsID for the newly created record
    SELECT SCOPE_IDENTITY()
  8. Select the Insert Query and in the Properties box, change ExecuteMode is Scalar
  9. Going back to your code (or BLL) where you initiated the table adapter, you can access your id using
    int x = Convert.ToInt32(myTableAdapter.InsertQuery(……..));
  10. Remember the convert to else it will give an object error. And Volia! You get the damned product ID.

Pardon my french but this is oddly simple and frustrating to work with.