How To Do For Loop With Controls

Mar 9, 2011

For Each Control In Page.Header.Controls How can I do something as above, at the moment getting the error "Control is a Type and Cannot be used as an expression" The Complete Code is as follows Try ' I only do this on my production servers, so I declare those here.'

If Request.ServerVariables("server_name") = [URL] Then
' Allow scripts and css to logged in CMS users'
Dim checkLogin As New Controls.Login
If checkLogin.IsLoggedIn <> True Then
For Each Control In Page.Header.Controls
If Control.GetType.Name = "EktronJsControl" Or Control.GetType.Name = "EktronCssControl" Or Control.GetType.Name = "EktronModalCss" Then
Page.Header.Controls.Remove(Control)
Else
' Removes the extra bubble inline style stuff that wasn't put in a CSS.''
Dim litControl As LiteralControl = Control
If litControl.Text = Nothing Then
litControl.Text = ""
End If
' Removing blank.css file'
Dim htmlLink As HtmlLink = Control
If htmlLink.Href = "/css/blank.css" Then
Page.Header.Controls.Remove(Control)
End If
End If
Next
End If
End If
Catch ex As Exception
End Try`

View 5 Replies


Similar Messages:

Delaring A String Thats Within A Loop Within Another Loop

Jan 14, 2010

Im stuck with declaring a string which is in a loop within another loop.

Dim CompanyDetails As String = ""
Dim CompanyRow As DataRow
For Each CompanyRow In newdt.Rows
CompanyDetails += CompanyRow(1) & " " & CompanyRow(0) & "<br/>"...

How can I get this to see the GetInfo as declared..... since its in a loop within a loop?

View 9 Replies

C# - Loop Through All Controls On Webpage

Nov 23, 2010

I need to loop through all the controls in my asp.net webpage and do something to the control. In one instance I'm making a giant string out of the page and emailing it to myself, and in another case I'm saving everything to a cookie. The problem is masterpages and items with collections of controls inside them. I want to be able to pass in a Page to the method, then have that method be generic enough to loop through all controls in the inner-most content page and work with them. I've tried doing this with recursion, but my recursion is incomplete. I want to pass a Page object into a method, and have that method loop through all controls in the innermost content page. How can I achieve this?

private static String controlToString(Control control)
{
StringBuilder result = new StringBuilder();
String controlID = String.Empty;
Type type = null;
foreach (Control c in control.Controls)
{
try
{
controlID = c.ID.ToString();
if (c is IEditableTextControl)
{
result.Append(controlID + ": " + ((IEditableTextControl)c).Text);
result.Append("<br />");
}
else if (c is ICheckBoxControl)
{
result.Append(controlID + ": " + ((ICheckBoxControl)c).Checked);
result.Append("<br />");
}
else if (c is ListControl)
{
result.Append(controlID + ": " + ((ListControl)c).SelectedValue);
result.Append("<br />");
}
else if (c.HasControls())
{
result.Append(controlToString(c));
}
//result.Append("<br />");
}
catch (Exception e)
{
}
}
return result.ToString();
}
Without Try/catch
Object reference not set to an instance of an object.
On line controlID = .....

View 2 Replies

C# - Loop Through Controls Of UserControl?

Sep 30, 2010

I have a user control with 5 simple radiobuttons, I need ot loop through those in code-behind, but I am drawing a huge blank on how to do this.

View 3 Replies

Custom Server Controls :: Rendering Controls Via Loop Inside Render

Nov 11, 2010

I am creatin a server control where some controls are being rendered inside `protected override void Render(HtmlTextWriter writer)`

writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo1");
writer.AddAttribute(HtmlTextWriterAttribute.Value, "Button1");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag(); //button
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo2");
writer.AddAttribute(HtmlTextWriterAttribute.Value, "Button2");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag(); //button

This way buttons are rendered on design view as well. The problem is that number of buttons to render is dynamic based on data in xml file (even if the data was static, the number of button is about 12 and I don't think it is wise to copy paste the same code above 6 times...). I thought by using loop for that:

int i = 1;
foreach (Button button in tb.Items)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo" + i);
writer.AddAttribute(HtmlTextWriterAttribute.Value, button.ButtonValue);
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag(); //button
i++;
}

tb is defined in OnLoad; On run time it works, but on design time I get error: > Error rendering control. And control is not being rendered.

View 1 Replies

Forms Data Controls :: Loop To Create Controls Dynamically From Database?

Jun 21, 2010

I would like to find out if there is anyone who would know how to read from a database then returns the same number of records that a stored procedure returns and display those records on the webpage there after pass the ID of the record to a variable to another stored procedure that displays the data related to the record that was clicked, I tried doing this in a asp.net repeater but I can't seem to be able to reference the controls inside the repeater.

<Repeater HTML Code>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OpenLogs.aspx.cs" Inherits="OpenLogs" EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

[Code]....

View 1 Replies

Linq - C# - Loop Through Certain Controls On A Page?

Feb 25, 2011

I am currently looping through all the controls on my page and setting certain types (TextBox, CheckBox, DropDownList, etc.) to Enabled=False under certain conditions. However I notice an obvious page load increase looping like this. Is it possible to only get certain types of controls from the Page.Controls object rather than Loop through them all? Possibly with something like LINQ?

View 3 Replies

DataSource Controls :: Loop Through Reader Using VB?

Jan 7, 2010

how I can loop through the results in VB, I only ever seem to get the last row, I would like to list all rows.

My code is below

[Code]....

View 3 Replies

C# - Loop Through All The User Controls On A Page?

Apr 13, 2010

Want to loop through all the user controls that exist on the page and get their IDs. How do I do it?

View 3 Replies

Web Forms :: Reading Controls Value Using Loop?

Jul 5, 2010

I need to read textbox values or any control

assume that i have 10 textboxes with ID's txt1 , txt 2 ..... txt10

is there any possible way to read them using loop like for to next or any loop control ??

View 2 Replies

Forms Data Controls :: Loop Through Gridview Row Controls - Set Visible?

Feb 25, 2010

I'm trying to loop through a manually created row's controls in a gridview and set the visible property.

I can use findcontrol and it works fine and I don't have to loop. But there are a lot of controls, so I just wanna do it in a loop. But it never finds the control type I'm looking for. Here's my code:

[Code]....

View 1 Replies

Data Controls :: Loop And Add Label And LinkButton Controls To DataList

Sep 20, 2015

I am trying to search the database using Data List and Item Template. I just want to loop the data's from database in a linkbutton and a lable row by row. 

DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Description", typeof(string)));
dt.Columns.Add(new DataColumn("Auctionno", typeof(string)));

[Code] ....

View 1 Replies

Web Forms :: Loop Through Controls And Find Radiobuttonlist Controls?

Dec 13, 2010

I have a web page with several panels. I one particular panel, I have several radiobuttonlist controls. I added a LinkButton to my web page and when clicked, I want to clear the values in all my radiobuttonlist controls. I have this so far:

Protected Sub ClearRBL(ByVal sender as Object, ByVal e as EventArgs) Handles lbClear.Click
Dim ctl as Control
For Each ctl In Page.Controls
If TypeOf ctl Is RadioButtonList Then
DirectCast(ctl, RadioButtonList).ClearSelection()
End If
Next
End Sub

But this does not work. The If TypeOf ctl Is RadioButtonList Then line never finds a RadioButtonList control. How can I make this work?

View 3 Replies

How To Loop The Server Controls And Clearing Values

Jan 4, 2010

I have some server controls both textboxes and drop down list box's that I placed on a panel control. My question is I would like to loop through the controls textboxes and drop down list and clear all values.

View 9 Replies

DataSource Controls :: Loop Through The Records Of A Table?

Mar 19, 2010

im learning t-sql, infact i needed its while-loop to loop through records of a table, i found this code in some book:

[Code]....

i understand here that setting the rowcount variable to 1 will force the select statements to return only one record, do all above select statements return one record only?

if the underlined select statement returns one record everytime it is executed, isn't it supposed to return the same first record of the table everytime? is there a better way to loop through a table's records?

View 9 Replies

Forms Data Controls :: Loop Through Listview And Get 1st Value Of Each Row

Jun 1, 2010

I just cannot figure out how to do this. How do I get the 0 index item from each row of a listview? Here is what I have so far.

[Code]....

View 2 Replies

DataSource Controls :: How To Add New Rows To Datatable Using Loop

Feb 26, 2010

iam working with gridview in asp.net3.5,Sqlserver2008 I am retrieving data from a SP into a datatable.i need to store this table into gridview. but am getting the last row from my datatable into my gridview.

here i need to add each row to the datatable.

my grid is like this:

[Code]....

View 5 Replies

DataSource Controls :: Datareader - Loop Through Results In VB?

Feb 1, 2010

I would like to loop through my result set and generate a menu structure like this:

pagetitle
pagetitle
subtitle
subtitle
pagetitle
pagetitle

So far I have the following code but it doesn't generate the menu?

While reader.Read()
' set title
sitetitle = reader.Item("siteName")
mydata &= reader.Item("pagetitle")
' check subtitle exists, if so, build menu, loop though subtitles somehow?
if not IsDBNull(reader.Item("subtitle"))
mydata = "<ul>"
mydata &= "<li>" & reader.Item("subtitle") & "</li>"
mydata &= "</ul>"
end if
End while

Qeury and result set below:

sql:

SELECT subpages.subpageid, pages.pageid, sites.sitename, sites.siteid, pages.siteid,pages.pagetitle, subPages.subtitle FROM pages LEFT JOIN sites ON pages.siteid = sites.siteid LEFT JOIN subpages ON subpages.subpageid= pages.pageid WHERE sites.siteID = 1 ORDER BY sites.siteid, pages.pageid, subpages.subpageid ASC

results:

subpageid | pageid | siteid | siteid | pagetitle | subtitle
NULL 1 SCHS 1 1 Sandwell Community Healthcare Services NULL
NULL 2 SCHS 1 1 About Us NULL
NULL 3 SCHS 1 1 Your Services NULL
4 4 SCHS 1 1 Equality and Diversity Team at SCHS 1111
4 4 SCHS 1 1 Equality and Diversity Team at SCHS 2222
4 4 SCHS 1 1 Equality and Diversity Team at SCHS 333
4 4 SCHS 1 1 Equality and Diversity Team at SCHS 44444
NULL 5 SCHS 1 1 Single Equality Scheme NULL
NULL 6 SCHS 1 1 Diversity Strands NULL
NULL 7 SCHS 1 1 Equality Impact Assessments NULL
NULL 8 SCHS 1 1 Quality and Safety Committee NULL
NULL 9 SCHS 1 1 Contact Us NULL

View 5 Replies

JQuery :: Loop Through Dynamically Created Controls?

Oct 15, 2010

I'm trying to use the following loop to loop through dynamically created controls on my web form:

for(x = 0; x <= count; x++) {
Stmt += $("#DDLColumns" + x).val();
switch($("#DDLConditional" + x).val()) {

[code]...

View 1 Replies

Loop Through Controls That Follow A Naming Convention?

Jan 12, 2011

I have ten textboxes (txtCO1, txtCO2... txtCO10).I need to set them all to the same text (blank). How can I use a for loop that just changes the number after txtCO, isntead of explicitly setting each text box's text property to ""?

View 6 Replies

Forms Data Controls :: Loop Through GridView?

Dec 10, 2010

How do I loop through a GridView (the actual GridView, not its data source) to check what's displayed in the first cell (a BoundField with int data) of every row?

View 4 Replies

Javascript To Loop Through All Asp:Hyperlink Controls On A Page And Hide Them

Sep 21, 2010

I have a master page which has a DIV with asp:Hyperlink controls functioning as the menu for the site. When I'm on a certain page if (document.title = 'Certain Page'), I want javascript which will loop through all asp:hyperlink controls on the page and hide them (i.e. set to not visible). I know I could probably do this on the server side with less effort, but I'd rather do it via javascript.

View 3 Replies

Forms Data Controls :: Loop Through Gridview And Set Row Backcolor?

Feb 9, 2010

Is it possible to loop through a gridview and based on if a checkbox is checked, then change the backcolor to that current row? I have gave a few attempts, but luck.

[Code]....

View 6 Replies

DataSource Controls :: DataTable Foreach Loop - Continue To Next Row?

Mar 11, 2011

How can I continue to the next row in the foreach loop below.

[code]....

View 9 Replies

Forms Data Controls :: Loop Through Bulk Gridview?

Dec 15, 2010

I have a Bulk Gridview(all rows are editable) I need to loop through.I need to get the text that's displayed in each of the textboxes in the gridview, my current code is this:

[Code]....

like this, I need to loop through the gridview, but instead of just getting the text in each column, I need to get the text from the textboxes. How can I do that?If i'm going to use findcontrol() then I need the ID of each control. the gridview is always created dynamically, which means I don't know the number of controls that's being created beforehand. So, how/where can I find the ID?Is there another way to extract data from the textbox, other than findcontrol()?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved