But instead of manually writing out each controlID and setting its attribute with the line above, I had hoped there was a way to go through and set the attribute on each control ID if it had class=leftcolumn.
This is something I know is possible to do through JQuery easily, but I need it on the code behind during load.
I am developing asp.net mobile application. I am using LINQ to XML to query XML file. I am using the following query to retrieve the name & value of the query dynamically as follows
var TotalManifolds = from MF in FieldRoot.Element("FIELD-DEFINITION").Element("MANIFOLDS").Elements("MANIFOLD") join SLT in FieldRoot.Element("FIELD-DEFINITION").Element("SLOTS").Elements("SLOT") on (string)MF.Attribute("MID") equals (string)SLT.Attribute("PARENT") select new { SlotName = (string)SLT.Attribute("NAME").Value, SlotValue = (string)SLT.Attribute("NAME").Value };
In the following statement of above query I want to retrive the name of the attribure dynamically without explicitly specifying the name of the attribute SlotName = (string)SLT.Attribute("NAME").Value Here I am explicitly specifying the name. I want to code which can dynamically retrieve the name of the attribute. I am new to Linq to xml. how this can be done programatically? or can you provide me the link through which I can resolve the above issue ?
I'm creating an quiz application which queries the database and extracts the questions and choices. I use dynamically created controls such as a checkbox list and fill the values dynamically. How do I do this? Right now I have these functions:
array_random_init(); this creates a 10 element integer array from 1-20 - extract_question(i): this extracts a question indexed at i in DB, I created the controls and set the appropriate text in this function. - validate_question(i); this is called by button_click and validates the question i according to DB.
I understand I have to recreate the controls in Page_init on postback, but what should it look like? Do I need to add "if IsPostBack" in page_init, or do I create the controls in page_init() and reset their properties in page_load when I use extract_question(i)? Also, I cannot seem to clear the selected boxes on postback, I added page directive "enableviewstate=false" but it doesn't work.
I have a long running asynchronous process which returns a total of around 10-100 results over a 5 minute period. I want to update the page with the progress of the job and also show each result on the page in a list that grows dynamically as results are returned, all without any postback or page refresh.
I am using cascading dropdown list where the no of dropdowns is created dynamically on the page. The cascading drop downs are contained in a User Control. I need to call a method from the Parent page which will be executed when the values in one of the dropdowns change. The server side event is not firing as I have set AutoPostback property for the dropdownlists to be false. How can i make the Page event fired from the Selected index changed of the dropdowns keeping the autopostback property to be set as false.
How do I create an ASP.Net MVC Helper for an Html.Label which takes in attributes? Currently when I define an Html.TextBox I am able to pass in a list of attributes. Sort of like below:
new {disabled="disabled", @class="pcTextBoxWithoutPaddingDisabled"})%>
However, it does not look as though the Html.Label has this feature. As a result, I have to define my labels using the label tag. Sort of like below: <label class="pcLabelBlackWithoutPadding"> I would like to be consistent I how my Html element get created. So, how do I create an Html.Label that will take in a list of attributes?
I have an AJAX Reorder List control, which is working fine. I want to add an "Edit" hyperlink to the ItemTemplate (which I have done) that opens an AJAX Modal Window when it's clicked. I need to add an OnClick attribute to call a javascript function and pass the value for the ID of the object bound to the list. I have done this before with a gridview with no problem - I just need to add code like this to RowDataBound event: If e.Row.RowType = DataControlRowType.DataRow Then Dim HyperLink1 As HyperLink = e.Row.FindControl("HyperLink1") HyperLink1.Attributes.Add("onclick", "ShowPopup('" & myGridControl.DataKeys(e.Row.RowIndex).Value & "')")
This is allowing my application user to show up a different Site Map as and when the theme is changed.
But when I tried to do the same with the following code I faced with an issue.
configuration = WebConfigurationManager.OpenWebConfiguration("~") section = CType(configuration.GetSection("system.web/siteMap"), SiteMapSection) Dim provider As New ProviderSettings() If Not section Is Nothing Then provider.Name = txtError.Text provider.Type = "System.Web.XmlSiteMapProvider" section.Providers.Add(provider) configuration.Save() End If
This code is not allowing a provider.siteMapFile property (provideer is the ProviderSettings object). As well the maximum possible way I can add a new SiteMap provider in web.config is as follows
public void btnAddContact_Click(object sender, EventArgs e) { IList<CustomerContactProfile> customerContacts = new List<CustomerContactProfile>(); if (ViewState["CustomerContactList"] != null) customerContacts = (List<CustomerContactProfile>)ViewState["CustomerContactList"]; CustomerContactProfile contactProfile = (CustomerContactProfile)LoadControl("~/Controls/Embedded/CustomerContactProfile.ascx"); customerContacts.Add(contactProfile); foreach (CustomerContactProfile contact in customerContacts) phCustomerContacts.Controls.Add(contact); ViewState["CustomerContactList"] = customerContacts; }
This code doesn't work because the ViewState can't handle storing all of that control data. However, I cannot think of another way to store the controls that were already added.
The viewstate of the asp:PlaceHolder control doesn't save anything and I need the controls to be saved so that if a user puts in some data to the first control that the data isn't lost when they add a second one and so on.
Is there a way to list on the fly all fields in object context? in entity framework?
for example in my Log (object context) i have fields LogId, Name, CreateDate
I would like to loop through these dynamically and assign values. This would be useful when my current context changes to another table I would be doing this:
I have a database with some data in. Now I'm trying to show that data on my page whit a ListView.
For each object from the database a ListView will generate a dropdownlist.
I also have a DataPager on my page and this is where the problem occurs.
Each object generated from the database has a field that may look like this example.: 1,2,3.
In my code now I´m trying to split this string of comma character and add new items to my dropdownlist.
This works as long as I do not have DataPager on. But if I choose to view an x number of pages at the time when the page loads, I have value in the dropdownlists, only on my first page.
I have grid view which databind from object datasource. my problem is i want to disply dynamic dropdown list on edit template based on the id which has in grid view. but still i can't figure out a way to do this.
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]; } }
I'm trying to create a list of image buttons dynamically, but I'm having trouble displaying the images. I'm using the Directory.GetFullPath method, but I don't think its the right thing to do.I've viewed the page, and the image path is showing as
'd:Hosting6238630htmlPropertiesCedarsext%20front.jpg'. I know this isn'r right and that it needs to be something like www.annereevelettings.co.uk/property/images..., but the question is, how do I do it?The page can be seen at the following address
I've a page main.aspx. This page has a button 'Settings'. When it is clicked, I load another aspx page settigns.aspx in a popup. Now in the settings.aspx i allow the users to add controls dynamically. For example the user can create 5 textboxes. When he saves it there, I need to get that controls to main.aspx.
So i need to move all the controls from one page to another page. I'm not able to think of a solution with user controls.