Click here to Skip to main content
15,914,416 members
Home / Discussions / C#
   

C#

 
AnswerRe: Unable to delete files using fileinfo object in VISTA - getting security problem Pin
#realJSOP22-Dec-08 2:25
professional#realJSOP22-Dec-08 2:25 
AnswerRe: Unable to delete files using fileinfo object in VISTA - getting security problem Pin
Tom Deketelaere22-Dec-08 2:49
professionalTom Deketelaere22-Dec-08 2:49 
GeneralRe: Unable to delete files using fileinfo object in VISTA - getting security problem Pin
Rajesh Naik Ponda Goa22-Dec-08 17:19
Rajesh Naik Ponda Goa22-Dec-08 17:19 
Questionloop controls one by one Pin
DEEPNORTH22-Dec-08 1:18
DEEPNORTH22-Dec-08 1:18 
AnswerRe: loop controls one by one Pin
Ravi Bhavnani22-Dec-08 1:33
professionalRavi Bhavnani22-Dec-08 1:33 
GeneralRe: loop controls one by one Pin
DEEPNORTH22-Dec-08 15:20
DEEPNORTH22-Dec-08 15:20 
AnswerRe: loop controls one by one Pin
User 665822-Dec-08 1:40
User 665822-Dec-08 1:40 
AnswerRe: loop controls one by one Pin
nishu00727-Dec-08 2:49
professionalnishu00727-Dec-08 2:49 
private void CreateTextBoxes()
{
for (int counter = 0; counter <= NumberOfControls; counter++)
{
TextBox tb = new TextBox();
tb.Width = 250;
tb.Height = 60;
tb.TextMode = TextBoxMode.MultiLine;
tb.ID = "TextBoxID" + (counter + 1).ToString();
// add some dummy data to textboxes
tb.Text = "This is textbox " + counter + " data";
phTextBoxes.Controls.Add(tb);
phTextBoxes.Controls.Add(new LiteralControl("
"));
}
}

In CreateTextBoxes method I loop through ‘n’ numbers of controls that we wants to create dynamically in phTextBoxes placeholder.


// Add DropDownList Control to Placeholder
private void CreateDropDownBoxes(DataTable dtTable)
{
for (int counter = 0; counter <= NumberOfControls; counter++)
{
DropDownList ddl = new DropDownList();
ddl.ID = "DropDownListID" + (counter + 1).ToString();
int nTotalRecords = dtTable.Rows.Count;
for (int i = 0; i < nTotalRecords; i++)
{
ddl.Items.Add(dtTable.Rows[i]["item"].ToString());
}
phDropDownLists.Controls.Add(ddl);
phDropDownLists.Controls.Add(new LiteralControl("


"));
}
}

In CreateDropDownBoxes method I have done the same thing by looping through ‘n’ numbers of controls, the value of ‘n’ which was stored in ViewState, and create them in a phDropDownLists placeholder control.

// Create TextBoxes and DropDownList data here on PostBack.
protected override void CreateChildControls()
{
// Here we are recreating controls to persist the ViewState on every post back
if(Page.IsPostBack)
{
CreateTextBoxes();
InitializeDropDownBoxes();
}
// Create these conrols when asp.net page is created
else
{
CreateTextBoxes();
InitializeDropDownBoxes();
// Increase the control value to 1
this.NumberOfControls = 1;
}
}

CreateChildControls method, here we are recreating control on every PostBack. If the page is created the first time we just create these controls and save 1 in the ViewState so we know that we have created these controls and assigned the controls id to 1.


// Increase the counter when button is clicked and add to view state
private void btnAnotherRequest_Click(object sender, System.EventArgs e)
{
NumberOfControls += 1;
}

In button event handler we just increase the counter by 1, and save its value to ViewState for later retrieval.



Once we have created these controls on ASP.NET page, retrieving data from these dynamically created controls is easy by using FindControl method.

// Read DropDownList Data
private void ReadDropDownLists()
{
int n = this.NumberOfControls;

for (int i = 0; i<n;>{
string DropDownListName = "DropDownListID" + (i+1).ToString();
DropDownList ddl = phDropDownLists.FindControl(DropDownListName) as DropDownList;
lTextData.Text += ddl.SelectedValue + "
";
}
}

And

// Read TextBoxes Data
private void ReadTextBoxes()
{
int n = this.NumberOfControls;
for (int i = 0; i<n;>{
string boxName = "TextBoxID" + (i+1).ToString();
TextBox tb = phTextBoxes.FindControl(boxName) as TextBox;
lTextData.Text += tb.Text + ("
");
}
}






Questionover a $1000 to be won in coding competition Pin
sanj_8038822-Dec-08 1:08
sanj_8038822-Dec-08 1:08 
AnswerRe: over a $1000 to be won in coding competition Pin
Brij22-Dec-08 1:52
mentorBrij22-Dec-08 1:52 
QuestionUpdate database from DataGridView? Pin
kbalias22-Dec-08 1:03
kbalias22-Dec-08 1:03 
AnswerRe: Update database from DataGridView? Pin
vlinker22-Dec-08 2:20
vlinker22-Dec-08 2:20 
AnswerRe: Update database from DataGridView? Pin
Vimalsoft(Pty) Ltd23-Dec-08 2:25
professionalVimalsoft(Pty) Ltd23-Dec-08 2:25 
Questionmerge two images in a single picturebox Pin
jaraldumary22-Dec-08 0:43
jaraldumary22-Dec-08 0:43 
RantRe: merge two images in a single picturebox Pin
Smithers-Jones22-Dec-08 2:38
Smithers-Jones22-Dec-08 2:38 
AnswerRe: merge two images in a single picturebox Pin
Dave Kreskowiak22-Dec-08 4:25
mveDave Kreskowiak22-Dec-08 4:25 
QuestionHow to set the Pagesettings in Reportviwer Pin
Exelioindia22-Dec-08 0:25
Exelioindia22-Dec-08 0:25 
Answersample code Pin
jaraldumary22-Dec-08 0:47
jaraldumary22-Dec-08 0:47 
AnswerRe: How to set the Pagesettings in Reportviwer Pin
Tom Deketelaere22-Dec-08 1:19
professionalTom Deketelaere22-Dec-08 1:19 
GeneralRe: How to set the Pagesettings in Reportviwer Pin
Exelioindia22-Dec-08 1:53
Exelioindia22-Dec-08 1:53 
GeneralRe: How to set the Pagesettings in Reportviwer Pin
Tom Deketelaere22-Dec-08 2:43
professionalTom Deketelaere22-Dec-08 2:43 
QuestionSocket Connections Pin
Rick van Woudenberg22-Dec-08 0:02
Rick van Woudenberg22-Dec-08 0:02 
AnswerRe: Socket Connections Pin
Mark Salsbery22-Dec-08 7:52
Mark Salsbery22-Dec-08 7:52 
QuestionRuntime Report Formating.... Pin
zeeShan anSari21-Dec-08 23:40
zeeShan anSari21-Dec-08 23:40 
QuestionMark field in child class as NonSerialized Pin
Dust Signs21-Dec-08 23:34
Dust Signs21-Dec-08 23:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.