I am using jquery ajax method on my aspx page,which will invoke the webmethod in the code behind.Currently the webmethod takes a couple of parameters like firstname,lastname,address etc which I am passing from jquery ajax method using
now my requirement has been changed such that,the number and type of parameters that are going to be passed is not fixed for ex.parameter combination can be something like fname,city or fname,city or city,lname or fname,lname,city or something else.So the webmethod should be such that it should accept any number parameters.I thought of using arrays to do so, as described here.
But I do not understand how can I identify which and how many parameters have been passedto the webmethod to insert/update the data to the DB.
I need to update a table with values from a listbox. I am trying to create as many parameters as there are items in the list, my code below, but how do i name them differently? so that they dont' overwrite each other?
For Each item As ListItem In ris Dim pID As New SqlParameter("@userid", SqlDbType.Int) pID.Value = objFormat.CheckSQL(item.Value) myCommand.Parameters.Add(pID) Next
and on the SQL side, is it possible to write an update statement, that will take a dynamic number of parameters?
so for example, i need to update multiple users with the same value in the "active" field...
I have a dynamic created drop down list - and I set the event of it to be like this:
ddlAnswer.ID = "ddlistAnswer" + QuestionID; ddlAnswer.SelectedIndexChanged += new EventHandler(ddlAnswer_SelectedIndexChanged);
Please note that drop down list is dynamic, and in selectedIndexChanged, I would like to pass the "QuestionID" to that selectedindexchanged to work on my logic. Is there a way to pass it to that method as command argument or something?
Code: protected void ddlAnswer_SelectedIndexChanged(object sender, EventArgs e) { //wanting that question id here }
I know parameters to attribute declarations have to be a constant expression and resolved at compile time. However, can I play with the concept of 'compile time'? ASP.net has the concept of App_Code folder. It looks from it's description like you can drop .cs files into it, even while the app is running, and it will be brought in and compiled. Is it possible to use this mechanism to dynamically create an Enum or const array that can be used in an attribute declaration?
[SomeAttribute(ValidTypes.SomeType)] public class Foo { }
Basically, I want to dynamically grow the valid types in ValidTypes without having to recompile all components that reference it. And I need to keep it in sync with a list of values in a database table. So, my question is, can I drop a .cs file with the definition for an Enum or const string array into App_Code and have it automagically show up? Or better yet, is the mechanism .Net uses to do this available to be called elsewhere so I don't have to do it in an ASP.Net app?
I am going to return an Object depending on the Class and Year params. I want to remove the where condition when the Class and Year parames are null or zero.
I just struck upon a prime opportunity to further exhibit my MVC ignorance, by way of the following: How can one make use of a custom view model class that has parameters in the constructor? For example, a class that could intitialize various collections/properties based on an IPrincipal object passed in. I've come across several allusions to this scenario, involving a class inheriting DefaultModelBinder which overrides the CreateModel method, but have yet to find an example.
I've a requirement that I need to read an excel sheet programmatically using asp.net/C# and write the data obtained into a mysql table.The excel sheet contains something around 50 columns and 2000 records.I am able to read the data from the excel sheet and store it in a dataset.I am using the following code to write the data into mysql table.
for (int i = 1; i <= myDataSet1.Tables[0].Rows.Count - 1; i++) { MySqlCommand cmd = new MySqlCommand(); for (int j = 0; j <= myDataSet1.Tables[0].Columns.Count - 1; j++) { paramset[j] = myDataSet1.Tables[0].Rows[i][j].ToString(); cmd.Parameters.AddWithValue("val" + j, paramset[j]); } cmd.CommandText = "Insert into faqimport cmd.Connection=con; cmd.CommandType = CommandType.Text; int x=cmd.ExecuteNonQuery; }
When I try to run the above code I am getting 'Unknown column 'val0' in 'field list'' error.I understand that i am manually creating the parameters val0,val1,val2.....instead I am creating them dynamically using the integer 'j'.But I do not want to create around 50 parameters to insert data into the database table.
Also is there a way i can get the column datatypes from the excel sheet in order to create a new table in mysql with the columns in the excel sheet?
I have an ObjectDataSource3 that I am trying to use to insert data from:
From: Dropdownlist1.selected value To: (CustomerID) From: Dropdownlist2.selected value To: (ProductCode) From: txtTitle (Title) To: (Title) CurrentDate To: DateOpened The btnAdd event is suppose to calls: ObjectDataSource3.Insert()
Below is my code for both the page and class. Although my class is expecting parameters, I don't know how to get the parameters to the insert function in my class.
Using the properties as defined in a class, how about can I put them into the ParamArray parameters argument of my function. The code as follows:
Public Class MyObject Public Property Prop1 as string Public Property Prop2 as integer Public Property Prop3 as Boolean Public Sub AddNewMyObject MsSQL_ExecuteNonQuery("StoredProc_AddNewMyObject", ________________?) End Sub End Class Protected Function MsSQL_ExecuteNonQuery(ByVal storedProc as string, ByVal ParamArray parameters as object()) 'Some Code here. End Function
I want to create a function which would have two parameters
public **XYZ** GetOputput(string strToConvert, **ABC**)
What I want from this function, that I will send a string to this function and the datatype in which I want to convert this string [Ex: Int32,Int64, datetime etc..] and the return will be the same as the datatype I have sent as the input parameter.
I want to have something like this in my function:
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 got a design which I basicly use for 100's of websites, and have a virtual folder for masterpages with is copied from a project using build events.Each Masterpage (as this stage), I can rename them or change the names if it helps with this problem, but I need to be able to access the propertys in the masterpage code / dllso I have come up with this
I'm using Facebook SDK C# Library in Asp.Net 3.5 Application. When I'm trying to compile the code below give me the errors. As I know dynamic type using in 4.0 framework. So is anyway to rewrite it in order make it work? I have a reference to System.Core 3.5 but it's still not compiling
Error 1 Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference to System.Core.dll?
Error 2 Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference to System.Core.dll?
Im new to ASP.NET. Im trying to develop ecommerce web application and i found dynamic link building class and i dont understand how it works.
public class Link { // Builds an absolute URL private static string BuildAbsolute(string relativeUri) { // get current uri Uri uri = HttpContext.Current.Request.Url; // build absolute path [code]...
I have a vb.net class with properties defined as follows:
Private m_Property1 As String Public Property Property1() As String Get Return m_Property1 End Get Set(ByVal value As String) If IsNothing(value) Then m_Property1 = String.Empty Else m_Property1 = value End If End Set End Property
I can then set the values as follows:
classname.Property1 = "myvalue"
How do I set the value of a property that is defined dynmically eg
I programmed a WebForm where I can add dinamic FileUpload elements and upload a variable number of files. So far no problem.
My problem begins when I try to automate this process in a class Uploader (external to this webform so it can be called from any other form or module). In my form's Page_Load() I instantiate this class and call the method uploader.layout(Me), which definition you can see next:
[Code]....
I get an error
El control 'FicheroUpload1' de tipo 'FileUpload' debe colocarse dentro de una etiqueta de formulario con runat=server. Which means something like The control 'FicheroUpload1' of type 'FileUpload' must be set inside a form label with runat=server.
Where is the error? Can I insert dinamic elements in a form from an external function, such as this class method?
I have created a user control which is inside a folder called Controls and the class is a partial class which inherits from Web.UI.UserControl. Now from my page which is one level up I just try to access the method inside the usercontrol and so trying to cast it as the type of user control. But I get build errors. It just cannot recognize that class. I get Type not defined error. But at times it has recognized the class. Dont know why it does that.
I know this 'dyanamic control event not fired' has been raised time and time again, but I still can't work out how to solve this issue...
I'll break down the parts and where the button is created without the 'flesh' around the code that shouldn't have an effect.
Imagine this is the stack:
[Code]....
button_Click never gets fired. The annoying thing is in the app, if button list isn't used, RadioButtonList is and is attached in exactly the same way and while i haven't checked, i'd imagine I would be able to catch events from that.
1. I have a GridView on my page and it uses sqldatasource with parameterized query. What I want to do is, on page load (where nothing has been selected so no parameter supplied), I want it to query everything (something like SELECT * FROM [this_table]) but since my SelectCommand is something like
SELECT * FROM [this_table] WHERE [this_column] = @someParameters AND [that_column] = @someParameters.
Can I play around with default value to achieve something like that but how ? Now, when the page loads, it doesn't show anything (No Gridview).
2. On my page, I made something like (username, gender, address, and more) and one single search button. That means, no single control enable auto postback. What I am trying to accomplish is building dynamic query
(if username specifed -> SELECT * FROM [this_table] WHERE [username] LIKE @username).
If both username and gender are specified (SELECT * FROM [this_table] WHERE [username] LIKE @username AND [gender] = @gender) and you know the rest. How can I do this using GridView and SqlDataSource ? To my knowledge, I can only specify one SELECT statement in a sqldatasource.
I am feeling that I have terribly wrong somewhere. I was working on a small asp.net app. I have some dynamic themes in the heme folder and have implemented a page base class to load the master page on the fly. The master is having the ContentPlaceHolder like: <asp:ContentPlaceHolder ID="cphBody" runat="server" />
Now I am adding pages that are derived from my base class and added the form elements. I know, Visual Studio has problem showing the page in the design mode. I have a dropdown box and wish to add the event of onselectedindexchange. But it is not working. the page is like this: