LinqDataSource Dynamic Parameters - Forcing An Or With WhereParameters?

Jul 22, 2010

In my "selecting" statement I need to add two dynamic parameters when using the LinqDataSource's WhereParameters collection:

e.WhereParameters.Add(param, True)

However, the system adds these parameters as AND, but I want to perform an OR where either parameter 1 OR parameter 2 is true.

View 2 Replies


Similar Messages:

C# - Add WhereParameters To LinqDataSource In Selecting Event?

Mar 19, 2010

I have a repeater using a LinqDataSource as a data source. When a query string is entered, I'd like to filter the results, but ONLY when a query string is entered. If there is no query string, the results should not be filtered, all results should be returned.

I'm trying to add a WhereParameter to my LinqDataSource in the Selecting event of the LinqDataSource, but it's not working. Here's my code:

protected void ldsImages_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
if (Request.QueryString["id"] != null)
{
e.WhereParameters.Add("ImageTypeID", Request.QueryString["id"]);
}
}

View 3 Replies

DataSource Controls :: How To LinqDataSource Date Parameters

Jun 15, 2010

I need to retrieve data using a date as an input parameter. I created a WhereParameter and passed in a date value that I know to exist in the database, but no data is returned. Heres my code

[Code]....

Ive passed in '02/06/2010' as the date, in the database, the Startdate column has several values of '2010-06-02 13:08:50.503' so I guess its not being found because of the time part. Whats the best way to make sure that I retrieve the correct data ? Im not concerned about the time at all, I just need all rows for 02/06/2010.

View 3 Replies

C# - Dynamic Columns With LinqDataSource?

Aug 24, 2010

Im using LinqDataSource like that:

<asp:LinqDataSource ID="LinqDataSource3" runat="server" OnSelecting="LinqDataSource3_OnSelecting">
</asp:LinqDataSource>
And I have ASPxGridView
<dxwgv:ASPxGridView ID="ASPxGridView2" ClientInstanceName="ASPxGridView2Client"
runat="server" AutoGenerateColumns="False"
DataSourceID="LinqDataSource3">
</dxwgv:ASPxGridView>

In this way Im able to add columns dynamically while handling onSelecting event:

protected void LinqDataSource3_OnSelecting(object sender, LinqDataSourceSelectEventArgs e)
{
MyModelDataContext context = new MyModelDataContext();
ASPxGridView grid = ASPxPageControl1.TabPages[3].FindControl("ASPxGridView2") as ASPxGridView;
if(grid.Columns.Count == 0){
GridViewDataTextColumn txtColumn1 = new GridViewDataTextColumn();
GridViewDataTextColumn txtColumn2 = new GridViewDataTextColumn();
txtColumn1.FieldName = "UserId";
txtColumn2.FieldName = "FirstName";
grid.Columns.Add(txtColumn1);
grid.Columns.Add(txtColumn2);
}
e.Result = from u in context.Users select new { UserId = u.UserId, FirstName = u.FirstName };
}

It is all made simply to test cause my idea is to have solution that makes it possible to use inqDataSource as a datasource for de ASPxGridView but join 2 or 3 tables and show results in this grid.

What I want to ask is if its good solution or is there any other better way to present some views made from couple of tables by join?

Second question is that I have Users and Group and I would like to have one table in which I would have two columns Name and Type For groups type would by group and for users type would be user. I dont have such a table in my database Is it possible to create specific class. Create List of objects of that class and fill it using linq query and the use it as linq data source for that grid ?

clas would be:

pseudocode:

Class MyClass {
string Type;
string Name;
}

or is there any other way to create such a table ?

View 1 Replies

C# - LinqDataSource Bound To Dynamic List?

Aug 17, 2010

Im trying to create LinqDataSource that will represent data from dynamically created String list and then use it as a datasource to my GridView.

List<string> users = RetreiveUsers();
LinqDataSource ds = new LinqDataSource();

View 1 Replies

How To Refresh The Gridview After It Filters (Dynamic) Using LinqDataSource

Jul 29, 2010

AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1">

SortExpression="UserName" />
SortExpression="FullName" />
SortExpression="Email" />
SortExpression="LastLoginDate" DataFormatString="{0:dd MMMM yyyy}"/>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="MyDataContextDataContext" onselecting="LinqDataSource_Selecting">
<WhereParameters>
<asp:Parameter Name="Subject" />
</WhereParameters>
</asp:LinqDataSource>
public void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
this.LinqDataSource1.WhereParameters["Subject"].DefaultValue = this.txtSubject.Text;
e.Result = reporterRepo.GetInquiries();

View 2 Replies

How To Get The Individual Parameters From The List Of Dynamic Parameters In A Webmethod

May 12, 2010

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

data:JSON.stringify({fname:firstname,lname:lastname,city:city})

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.

View 4 Replies

Binding Data From LinqDataSource To Textbox / How To Bind Texbox To One Property From Linqdatasource

Sep 1, 2010

How I can bind texbox to one property from linqdatasource?

I mean something like databinding contols in c# app

View 1 Replies

C# - Set A Parameter For WhereParameters In EntityDataSource?

Dec 29, 2010

I have an EntityDataSource and I need set WHERE to a Local Variable Type: GUID.

My problem is I am not able to send my local variable Guid to EntityDataSource for a WHERE OPERATION.

I also tried to to use a ControlParameter<asp:ControlParameter Name="UserId" /> and have a Label with Text property on my Guid converted in String. But does not work.

<asp:EntityDataSource ID="EntityDataSourceListAuthors" runat="server"
AutoGenerateWhereClause="True"
ConnectionString="name=CmsConnectionStringEntityDataModel"
DefaultContainerName="CmsConnectionStringEntityDataModel"
EnableFlattening="False" EntitySetName="CmsAuthors" Where=""
EntityTypeFilter="" Select="">
<WhereParameters>
<asp:Parameter Name="UserId" />
</WhereParameters>
</asp:EntityDataSource>

View 1 Replies

C# - Is It Safe Using Dynamic SQL With Parameters

Jan 12, 2011

For example, this is the code that I am using:

String commandString = "UPDATE Members SET UserName = @newName , AdminLevel = @userLevel WHERE UserID = @userid";
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconnectionstring"].ConnectionString))
{
SqlCommand cmd = new SqlCommand(commandString, conn);
cmd.Parameters.Add("@newName", newName);
cmd.Parameters.Add("@userLevel", userLevel);
cmd.Parameters.Add("@userid", userid);
conn.Open();
cmd.ExecuteReader();
Reader.Close();
}

View 3 Replies

Dynamic Parameters In A Stored Procedure?

Jan 19, 2011

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...

View 3 Replies

Use Dynamic Parameters In The RoutingExpressionBuilder Class?

Mar 24, 2011

Using routing in web forms in ASP.NET 4.0. Looking to use dynamic parameters in the RoutingExpressionBuilder class something like:

NavigateUrl="<%$ RouteUrl:searchterm={dynamicParameterFromObject} %>">

Would like to know the proper syntax is available.

View 1 Replies

Dynamic DropdownList Passing Parameters

Mar 6, 2013

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
}

View 1 Replies

Dynamic Parameters For Attributes - Drop .cs File?

Sep 28, 2010

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?

View 1 Replies

Passing Dynamic Parameters To A Mysql Query From Page?

May 20, 2010

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?

View 1 Replies

C# - Dynamic Return Type Based On The Input - Create A Function Which Would Have Two Parameters

Feb 14, 2011

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:

[code]....

View 5 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

C# - Forcing A Postback Asp.Net

May 12, 2010

Please take a look at the following click event...

Protected Sub btnDownloadEmpl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownloadEmpl.Click
Dim emplTable As DataTable = SiteAccess.DownloadEmployee_H()
Dim d As String = Format(Date.Now, "d")
Dim ad() As String = d.Split("/")
Dim fd As String = ad(0) & ad(1)
Dim fn As String = "E_" & fd & ".csv"
Response.ContentType = "text/csv"
Response.AddHeader("Content-Disposition", "attachment; filename=" & fn)
CreateCSVFile(emplTable, Response.Output)
Response.Flush()
Response.End()
lblEmpl.Visible = True
End Sub

This code simply exports data from a datatable to a csv file. The problem here is lblEmpl.Visible=true never gets hit because this code doesnt cause a postback to the server. Even if I put the line of code lblEmpl.Visible=true at the top of the click event the line executes fine, but the page is never updated. How can I fix this?

View 4 Replies

DataSource Controls :: SqlDataSource And Parameters Query / Trying To Accomplish Is Building Dynamic Query

Aug 22, 2010

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.

View 11 Replies

AJAX :: Forcing A Postback From An Asp.net Extender

Mar 12, 2010

I have been trying to figure out out to force a postback from an asp ajax extender. The closest post that I can find is

http://forums.asp.net/t/984558.aspx

However I am pretty sure this was at least one migration ago. Additionally I am using VB as my programming language so some of the conversion may be the problem.

I think I am pretty clear on what needs to be done.

If I am correct the steps are...

Create a new property in the extender to hold the postback command for each target control that is using the extender.

Then in the Onload populate that property (Use GetPostBackEventReference to get the ASP valid target ID ) so it can be called from the Clientbehavior.js

My problem is the syntax in the for-each loop that allows me to iterate through the target controls.

Protected Overloads Overrides Sub OnLoad(ByVal e As System.EventArgs)

View 1 Replies

Forcing The User To Type Just Numbers?

Jun 15, 2010

I have a TextBox and I want that the user type just numbers, not other format.

How can I do that ?

View 4 Replies

Visual Studio Forcing Indentation?

Feb 23, 2010

I am having a problem editing VB.NET .aspx pages in Visual Studio 2008. If I edit a line that is flush against the left margin, Studio automatically indents it 4 spaces, and there is no way to undo it! I am forced to save the file with that 1 line I edited indented differently than all the other lines!

Edit: How do I turn this off?

View 1 Replies

AJAX ::Forcing A User To Use Autocomplete?

Mar 12, 2011

I have a textbox that the user is supposed to enter "City, State". I also have a geoIP lookup that enters that information in for them. If that fails, they would enter it in, and autocomplete will suggest the city and state.The problem:

[code]...

View 4 Replies

C# - Forcing A Dropdown List For An Entity Property?

Jan 22, 2011

I'm trying to keep track of employees in my database. I have two tables, Employees and Departments. The Employees table contains a foreign key relationship with Departments through a column named DepartmentID.

Here's my entity:

[code]....

I have a page that contains a form to add an employee. I'm passing the entity to my view page, and calling <%: Html.EditorForModel() %>

The problem is that the view creates a textbox for the DepartmentID.

How can I force the view to display a dropdown for DepartmentID that contains all the Departments in my database as the dropdown's list items? Is there a way to do this by just adding a metadata attribute to the property in my entity?

View 1 Replies

AJAX :: Forcing Full Postback In UpdatePanel

Apr 19, 2010

I have basically the following structure set up :

[Code]....

I am aware that a FileUpload requires a full page postback. I read the article http://www.4guysfromrolla.com/articles/090209-1.aspx[^]I tried to install a PostBackTrigger programmatically to get a full postback only on the ImageButton1 control. All other postbacks must be partial. (GridView sorting, paging, ...)In code behind I do :

[Code]....

The above code does not seem to install a full postback only for the ImageButton1, so the file upload fails. How can I make this work ?

View 6 Replies







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