Dynamic - How To Dynamically Construct A Control Name

Mar 2, 2011

I am iterating through an array:

Dim dbConfig As New pbu_housingEntities
Dim possible() As String = {"FROD", "FRCD", "SOOD", "SOCD", "JROD", "JRCD", "SROD", "SRCD", "SR5OD", "SR5CD"}
For Each value As String In possible
Dim current_value = value
Dim exists = From p In dbConfig.Configs _
Where p.Description = current_value
Select p
If exists.Count.Equals(0) Then
Dim create As New Config
create.Description = current_value
dbConfig.Configs.AddObject(create)
dbConfig.SaveChanges()
Else
Dim update_query = (From p In dbConfig.Configs _
Where p.Description = current_value _
Select p)
update_query.First.Description = current_value
update_query.First.dateValue =
End If
Next

Towards the end of the array you can see update_query.First.dateValue =, I'd like to do something like this: update_query.First.dateValue = "txt" + current_value + ".Text" But I don't want it to return the literal txtcurrent_value.Text, but rather to return the text value of txtcurrent_value.Text. This is easy to do, if you know each control name - but in this case I'm iterating, otherwise I could do:

update_query.First.dateValue = txtNameofControl.Text

View 1 Replies


Similar Messages:

How To Construct A Control Like The ScriptManager

Jan 25, 2010

Maybe this is not the best title to it, but this is what I am trying to find out. I need a way to construct a control in ASP.Net that mimics the ScriptManager in that it should look like this:

[code]....

How to make the Control have a List of items that you can add items to from the Source of a page.

View 1 Replies

ADO.NET :: How To Construct System.linq.enumerable.where

Nov 29, 2010

I have a table "OSTAN" with two columns "ID" (Key index) and "NAME". I am trying to construct a linq query to select the Name for a specific ID. I have not luck trying to construct the where clause. Here what I have so far:

using (XeledsEntities db = new XeledsEntities())
{
string SelectedName = db.Ostans.Name.Where( Ostan=> Ostan.Equals(Request.QueryString["Ostan"])).FirstOrDefault();
}

Can anybody construct this where clause to set the Selected Name?

View 2 Replies

C# - Unable To Construct An Entity (complex) Object From A Query

Jun 8, 2010

I am very new to entity, sql, c#, and asp.net so this might be something easily fixed. I am attempting to display all the inactive products stored in my table called products in a datagrid.

var productQuery = from b in solutionContext.Version
where b.Product.Name == search && b.Product.ActiveNumber > b.VersionNumber
select new Product
{
Name = b.Product.Name,
Description = b.Product.Description,
ID = b.ID,
LastNumber = b.Product.LastNumber,
MiddleNumber = b.Product.MiddleNumber,
RSTATE = b.RSTATE,
ActiveNumber = b.Product.ActiveNumber,
LastModified = b.Product.LastModified,
ParentID = b.Product.ParentID,
ProductType = b.Product.ProductType
};
ProductsGrid.DataSource = productQuery;
ProductsGrid.DataBind();

I am getting this error: $exception {"The entity or complex type 'SolutionsModel.Product' cannot be constructed in a LINQ to Entities query."} System.Exception {System.NotSupportedException}

View 1 Replies

Web Forms :: Can Construct A Tree View From XML Retrieved From Database

Jul 20, 2010

I want to create a Tree View using XML that is fetched from SQL Server. How I can directly assigned to tree view, the below code I tried, but throwing error 'dsXML' is not an IHierarchicalDataSource. The XML heirarchy is proper. When I use XmlDataSource with the xml file, tree view is shown.

<asp:SqlDataSource runat="server" ID="dsXML" ProviderName="System.Data.SqlClient"
ConnectionString="Data Source=Server;Initial Catalog=database1;Persist Security Info=True;User ID=userid;Password=password"
SelectCommandType="StoredProcedure" SelectCommand="spGetXML">

[code]....

View 1 Replies

Databases :: How To Construct An Excel File Connection String With Full Path

Jan 14, 2011

I am trying to write a page to read the Excel file provided by the user. I know I can't use the FileUpload to get the full path of the file from the client PC. This give me the problem when I write the connection string for the Excel file:

[Code]....

Without the full path, I can't replace the Data Source by a variable and I definitely can't assume all users will have their Excel files named Book1.xls located in C:Doc all the time.

View 1 Replies

Web Forms :: Construct A Regular Expression For The Password Textbox Which Shouldn't Accept Special Characters

Sep 16, 2010

I need to construct a regular expression for the password textbox which shouldn't accept special characters($,@,!,etc).Even whitespaces,tabs. I tried the below this accepts special characters.

<asp:RegularExpressionValidator ID="RegEx" runat="server" ControlToValidate="Password"
ErrorMessage="Password must be atleast 8 characters and include a number,alphabets upper case and lower case.
"ToolTip="Password format is not correct"
ValidationExpression="^(?=.{8})(?=.*d)(?=.*[a-z])(?=.*[A-Z]).*$">
</asp:RegularExpressionValidator>

View 3 Replies

Dynamic - Dynamically Adding A Commandbutton?

Apr 1, 2011

I have a page with a dynamically created command button. I need to dynamically wire up a click event so I can grab the CommandArgument of the clicked button.

Button b = new Button();
b.ID = "btnTrigger2";
b.CssClass = "hiddenBtn";
b.CommandName = "lbl3";
b.Click += new EventHandler(btnTrigger_Click);

The problem is the last line - I can't wire up an EventHandler this way - I need to use the standard EventArgs instead of CommandEventArgs. There's got to be a way.

EDIT

Figured I'd post the code that finally worked in case anyone else tries to do the same thing.

string tabLoadedScript = string.Empty;
string postBackScript = string.Empty;
string script = " <script language='javascript' type='text/javascript'>" + System.Environment.NewLine;
script += "function clientActiveTabChanged(sender, args) {" + System.Environment.NewLine;
int i = 0;
foreach(TabPanel tp in tc1.Tabs)
{
Button b = new Button();
b.ID = "btn" + tp.ClientID;
b.CssClass = "hiddenBtn";
b.CommandName = tp.ID;
b.Command += btnTrigger_Click;
this.form1.Controls.Add(b);
AsyncPostBackTrigger trg = new AsyncPostBackTrigger();
trg.ControlID = "btn" + tp.ClientID;
tabLoadedScript += "var isTab" + tp.ClientID + "loaded=$get('" + tp.Controls[0].ClientID + "');" + System.Environment.NewLine;
postBackScript += "if(!isTab" + tp.ClientID + "loaded && sender.get_activeTabIndex() == " + i + ") {" + System.Environment.NewLine;
postBackScript += "__doPostBack('" + b.ClientID + "','');}" + System.Environment.NewLine;
i++;
}
script += tabLoadedScript;
script += postBackScript;
script += "}" + System.Environment.NewLine;
script += "</script>";

this.ClientScript.RegisterClientScriptBlock(this.GetType(), "cs", script, false);
protected void btnTrigger_Click(object sender, CommandEventArgs e)
{
System.Threading.Thread.Sleep(2500);
Panel ctrl = (Panel) FindControlRecursive(this, "pnl" + e.CommandName);
ctrl.Visible = true;
}
public static Control FindControlRecursive(Control Root, string Id)
{
if(Root.ID == Id)
return Root;
foreach(Control Ctl in Root.Controls)
{
Control FoundCtl = FindControlRecursive(Ctl, Id);
if(FoundCtl != null)
return FoundCtl;
}
return null;
}

View 2 Replies

Dynamic - Adding <br/> Dynamically Between Controls?

Jun 22, 2010

I'm listing some controls at my web page dynamically, either I'm adding newline with Label's.

Label newLine = new Label();newLine.Text = "<br/>"; myPanel.Controls.Add(newLine);

How can I do it in a different way?

View 2 Replies

Dynamic - Dynamically Adding Controls In Page?

Feb 20, 2010

I am adding controls dynamically in my webpage.

I add them in onload method.

everything is working fine..

But I m a bit confused about how it works..

I have read in so many articles that all controls get their values from viewstate before load event. Then how my dynamically added controls get their values when i am adding them in OnLoad event ie after LoadPostData event.

View 2 Replies

Dynamic - Dynamically Loading Controls And Persistence?

Sep 1, 2010

I am loading a series of controls in the Page_Load event. However, I have to recreate those controls each page load, which means storing their data elsewhere. This is cumbersome.

protected void Page_Load(object sender, EventArgs e)
{
MyControl control = (MyControl)LoadControl(...);
control.Initialize(GlobalClass.controlData);
//^gives the control the data it had previously.
//Or use ViewState["controlData"] if serializable.
Controls.Add(control);
}

I feel like I should be using if (!IsPostBack) {}, but I don't know how, or why. In contrast, if I place the controls into the markup, then the controls seem to stay persistent. For example, a button in mark-up will remember any changes to its Text property (I think?).

<asp:Button ID="buttonText" runat="server"
Text="Text Segment" onclick="buttonText_Click" />

How do I maintain some sort of persistence with dynamically added controls, like controls added via mark-up? This would save me much work and frustration.

(I've coded for a small eternity, but the more I do ASP.NET, the more confused I become. Which is exactly the opposite of what how I understood learning to work :-P.)

View 2 Replies

Web Forms :: Dynamically Generated Dynamic Menu Items Width?

Sep 21, 2010

I have the following Menu:

[Code]....

[Code]....

It's being loaded from a dynamically generated XmlDataSource Item:

[Code]....

The XML of which looks something like this:

[Code]....

I can't seem to figure out a way to make the width of the drop menus consistent (they're following the padding conventions I have outlined, I get that). What I'm interested in is a way to make the DynamicItemsStyle width on all items the width of the widest one.

View 2 Replies

How To Update Dynamic Table In Database Through Dynamically Generated Text Box

Oct 17, 2012

I am creating a dynamic database table, inserting some records in dynamic table and generating update command dynamically. (This part is running ok)

Code:
// Create Table
public void createtable()
{
string sql = "CREATE TABLE " + txtTableName.Text.Trim() + "(" + "InfoCode nvarchar(MAX) NULL, UserName nvarchar(MAX) NULL, Mobile nvarchar(MAX) NULL, Email nvarchar(MAX) NULL";

[Code] ....

And in another page i am displaying the list of all the dynamic database tables. Here user selects table from gridview and the data is displayed to him in dynamically generated HTML Table with Dynamic textboxes. (This part is also running ok)

Code:

// Display data
protected void getTableInfo()
{
int RowNo = 0;
string NotCmd = "Select * From NTL Where InfoCode = @InfoCode";

[Code] ....

Now the problem is how to update the record in database through this dynamically generated html table and texboxes. When I run my dynamically generated update command, all the dynamic controls is lost in postback.

View 1 Replies

C# - How To Store/construct Complete Queries, As Using Simple SQL And Variables And "+"

Feb 12, 2011

I am not aware of the correct term used for the following procedure in LINQ but i hope there is a way.

SIMPLE SQL QUERY

select this from table where alpha would be this and that

To construct this sort of thing, I would (IS A REQUIREMENT) normally use variables like this:

[code]....

a thousand tables, i would have to write queries from all tables using there instance, to perform the exactly SAME TYPE select function!!!

what is the way around this

provide some links, source code examples, resources, books name.

View 1 Replies

Custom Server Controls :: Create Html Row And Cell Dynamically In Dynamic Gridview?

Feb 11, 2011

I am trying to create a composite control - A textbox, gridview and a button. When I create the grid dynamically, I use my function GridViewDataBind() that will basically create the gridview at runtime and bind it with data. In this method, I add a blank column (first column for expand/collapse image), databound columns (using custom Itemtemplate), a placeholder, then a new html row/cell and a child gridview. I want to know how can I add these html rows/cols to my gridview. Here is the code:

[Code]....

Not sure if the approach is right and if I was able to explain my problem?

View 5 Replies

C# - Selecting And Building A Control From A Control Library Dynamically, Using The Control Name From A Table?

Feb 1, 2010

I have a custom DDL that lives in my Server control library. Currently I add this control to a table by strongly typing the name of the control, the customary way.

Control_Library.Report_NumberDDL newDDL = new Control_Library.Report_NumberDDL();


What I want to be able to do is dynamically create that control by pulling the control name from a table. So I would have the name of the control in my code, in this case "Report_NumberDDL", and I would like to then create the control without having to strongly type it.

Something like this, though I know this doesn't work:

string controlName = "Report_NumberDDL";

Control_Library."controlName" controlNum1 = new Control_Library."controlName"();

Edit:I tried to do this:

Type type = Type.GetType("Control_Library.Report_NumberDDL");
object control = Activator.CreateInstance(type);

But on the CreateInstance(type) I get a null value exception. So the Type isn't getting created correctly.

View 1 Replies

Forms Data Controls :: Set Dynamic Text For Deletebutton And Dynamically Set The Delete Confirmation Message

Jan 20, 2011

I have a delete button in listview footer. I need to set dynamic text for this deletebutton and dynamically set the delete confirmation message also.Here is my code.

<asp:ListView ID="dlPictures" runat="server" RepeatDirection="Horizontal" DataKeyField="PictureId"
DataSourceID="OdsAlbumPictures" DataKeyNames="MappingId" ItemPlaceholderID="itemPlaceholder"
[code]...

I am getting server tags not well formed error..

View 2 Replies

Forms Data Controls :: Dynamic Gridview With Dropdownlist / Dynamically Set The List Values Based On Parameters (of The Row They Are On)

May 28, 2010

I'm new to web dev and c# so please bare with me. I am trying to create a dynamic gridview in a web form for users to to answer questions with (code below).

The dificulty im having is that i am nesting a dropdwonlist in the gridview and want to be able to dynamically set the list values based on parameters (of the row they are on). These values are in the main dataset for the gridview as each row represents a questionid and question text and then a ddl for the criteria...

I just don't know how to set the values for the dropdown all the code so far is below... just need to be able to populate the dropdowns with the relevant values.

I have created a stored proc to return the different criteria based on the questionid and questionGroupid which is the dataset that populates the other fields in the gridview: dbo.usp_QuestionCriteria @QuestionGroupId, @QuestionId

I have added this as a tableadapter called criteriaTableAdapter in a xsd file as well using the wizard... not sure if this is the right option though or just use the same method as i have for the other stored procedure as in the code below:

[CODE

]using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("usp_QuestionGroupDS", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada = new SqlDataAdapter(com);
DataSet ds = new DataSet();
ada.Fill(ds);
for (int i = 0; i < ds.Tables.Count; i++)
{
if (ds.Tables[i].Rows.Count > 0)
{
GridView gvDynamicQuestion = new GridView();
gvDynamicQuestion.Width = Unit.Pixel(700);
gvDynamicQuestion.BorderWidth = Unit.Pixel(0);
gvDynamicQuestion.Caption = "<div id="nifty" class="QuestionGroup"> <b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>" + ds.Tables[i].Rows[0]["Category"].ToString() + " Questions<b class="rbottom"><b
class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b></div>";
gvDynamicQuestion.AutoGenerateColumns = false;
gvDynamicQuestion.ShowFooter = true;
TemplateField tf = null;
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.DataRow);
tf.FooterTemplate = new DynamicGridViewTextTemplate(DataControlRowType.Footer, ds.Tables[i].Rows.Count);
gvDynamicQuestion.Columns.Add(tf);
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.DataRow);
gvDynamicQuestion.Columns.Add(tf);
tf = new TemplateField();
tf.HeaderText = "Criteria";
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Criteria", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewDDLTemplate();
gvDynamicQuestion.Columns.Add(tf);
////tf = new TemplateField();
////tf.HeaderText = "Criteria";
////tf.ItemTemplate = new DynamicGridViewDDLTemplate();
////gvDynamicQuestion.Columns.Add(tf);
gvDynamicQuestion.DataSource = ds.Tables[i];
gvDynamicQuestion.DataBind();
phDynamicGridHolder.Controls.Add(gvDynamicQuestion);
}
}
}
protected void DynamicGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
//
}
}
}
public class DynamicGridViewTextTemplate : ITemplate
{
string _ColName;
DataControlRowType _rowType;
int _Count;
public DynamicGridViewTextTemplate(string ColName, DataControlRowType RowType)
{
_ColName = ColName;
_rowType = RowType;
}
public DynamicGridViewTextTemplate(DataControlRowType RowType, int QuestionCount)
{
_rowType = RowType;
_Count = QuestionCount;
}
public void InstantiateIn(System.Web.UI.Control container)
{
switch (_rowType)
{
case DataControlRowType.Header:
Literal lc = new Literal();
lc.Text = "<b>" + _ColName + "</b>";
container.Controls.Add(lc);
break;
case DataControlRowType.DataRow:
Label lbl = new Label();
lbl.DataBinding += new EventHandler(this.lbl_DataBind);
container.Controls.Add(lbl);
break;
case DataControlRowType.Footer:
Literal flc = new Literal();
flc.Text = "<b>Total No of Questions:" + _Count + "</b>";
container.Controls.Add(flc);
break;
default:
break;
}
}
private void lbl_DataBind(Object sender, EventArgs e)
{
Label lbl = (Label)sender;
GridViewRow row = (GridViewRow)lbl.NamingContainer;
lbl.Text =DataBinder.Eval(row.DataItem, _ColName).ToString();
}
}
public class DynamicGridViewDDLTemplate : ITemplate
{
// Implementation of ITemplate
public void InstantiateIn(System.Web.UI.Control container)
{
// Create a DDL
DropDownList ddl = new DropDownList();
//Attach method to delegate
ddl.DataBinding += new System.EventHandler(this.ddl_DataBind);
container.Controls.Add(ddl);
}
//Method that responds to the DataBinding event
private void ddl_DataBind(object sender, System.EventArgs e)
{
//DropDownList ddl = (DropDownList)sender;
//DataGridItem container = (DataGridItem)ddl.NamingContainer;
//ddl.Data.Checked = [Data binding expression];
}
}

[/CODE]

View 7 Replies

Forms Data Controls :: Dynamic Size For Chart Control / Using The Control In Web Application

Feb 22, 2010

using the control in web application.

View 1 Replies

Creating Two Dynamic Control And Need Use The Break Line After Each Control?

Sep 7, 2010

I am creating two dynamic control and i need use the break line after each control. When i am trying response.write("<br>") in the behind code file it is not working. and my all controls get mixed and look very ugly.

[Code]....

how i can print each control in different line. i am printing more than 8 control using loop.

View 9 Replies

Web Forms :: Dynamic Control Creation In User Control?

Apr 19, 2010

i developed a custom control (inherited from System.Web.UI.UserControl) which is used within a Gridview's TemplateField:

<sc:MyControl
runat="server"
id="my_ctrl"
AllowEditing="true"
NumberOfControls='<%# Eval("Count")%>' />

"Count" is an integer value from the GridView Datasource.

Based on this value i have to create some LinkButtons dynamically in my custom control (in Page_Init), which works very well when the value for NumberOfControls is hard-coded.

My problem is that the value of "Count" is not available (NumberOfControls = null) during Page_Init and therefore i can't decide how many controls there should be generated.

Is there any way to pass databinded values to custom controls so that they can be used earlier (as if the values were hard-coded)?

View 2 Replies

Forms Data Controls :: How To Find Control Problem In Gridview While Adding Checkbox Control Dynamically

Mar 15, 2010

i have a gridview control i added checkbox contrl dynamically but i am not getiing the reference of checkbox in button clilck event here is my code Gridvew

[Code]....

.vb code

[Code]....

View 6 Replies

Generating Control Markup Based On A Dynamically Generated Control?

Dec 9, 2010

What I'm trying to do is take an instance of a control, and figure out what the markup would look like based on the property values set in the code behind. We've built a web-based web form designer. At the end of the design process we save the markup. For simple controls with supported types, generating the markup was easy. For complex controls with nested properties or unsupported types, we're faced with creating a custom markup generator for each custom control. I was hoping to find info out there that would jump start this development effort.

In simple terms, I have this:

Dim Ctl as Control = CType(Asm.CreateInstance("MyNameSpace.MyControl"), Control)
Ctl.Name = "Name of my control"

And I want to end up with this:

<cc1:MyControl ID="MyControl1" runat="server" Name="Name of my control" />

View 1 Replies

Web Forms :: Create Control Dynamically From A String Containing Control Name?

Mar 25, 2010

My scenario require's me to create a control from a string that contains the controls name, for example

string a = "TextBox";

using the above string a i need to create the control.Iam using Visual Studio 2008 Pro ASP.Net 3.5

View 4 Replies

ADO.NET :: LINQ Entity Framework Query - Construct "nested" Query?

Jan 22, 2011

I have a web app for our golf club. When I compute handicap index for each golfer, I have to select the most recent scores and then a subset of those scores depending on how many rounds of golf the golfer has played. All the scores are entered into a single SQL Express table called "Rounds". Verbally, this is what I'm trying to do:

1) select the twenty most recent golf scores (sort on date descending, "take(20)") [if less than 20 records, then select all available];

2) for this set of records, select the 10 lowest scores (or smaller number if golfer has less than 20 rounds);

3) compute the average round differential for the subset of records, etc. to calculate handicap index (this step is working ok...)

My current VB code has this LINQ query (which is flawed -- it selects the lowest handicap differential scores of ALL records for the filtered user):

[Code]....

How do I modify this query to accomplish items 1) & 2) above? It seems this should be simple, but my experience with queries is still limited.

View 2 Replies







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