C# - Passing Two Values Through CommandArgument And Splitting It?
Dec 7, 2010
I'm using the commandArgument property of the LinkButton ( Which is wrapped inside a repeater ) to pass two values -as one string- to a second repeater then I try to split them into two values, So I could use them as parameters in my ADO.NET Code (SqlCommand Parameters)....after testing my queries don't return any results but If I passed fixed values for the parameter or change the source of the parameter (just for test from a textbox or querystring or something) I get my results, so I think the problem is in splitting.
I Conduct some arugment values from the ArgumentCommand property of the LinkButton -which is wrapped inside a repeater:
<ItemTemplate>
<asp:LinkButton id="sort_lnkbtn" Text='<%# Eval("value")%>'
CommandArgument='<%#string.Format("{0}|{1}",Eval("arrange_by_id"),Eval("value"))%>' runat="server">
</asp:LinkButton>
</ItemTemplate>
Then I receive these values and cut them into two pieces of information:
string sortByAndArrangeBy = (e.CommandArgument).ToString();
char[] separator = { '|' };
string[] sortByAndArrangeByArray = sortByAndArrangeBy.Split(separator);
Now the ado.net code uses this values as a
using (SqlConnection cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
using (SqlCommand cm1 = new SqlCommand("SELECT [name] FROM brands WHERE (name like @SearchString + '%' )", cn1))
{
cm1.Parameters.Add("@SearchString", System.Data.SqlDbType.Char);
cm1.Parameters["@SearchString"].Value = sortByAndArrangeByArray[1];
cn1.Open();
using (SqlDataReader dr1 = cm1.ExecuteReader())
{
List_rpt.DataSource = dr1;
List_rpt.DataBind();
}
}
}
View 1 Replies
Similar Messages:
Nov 23, 2010
For a given MS SQL Database table of staff members, I'm using ASP to display each record line by line as follows:
So I've added 2 ImageButtons in an extra column and the problem I have is passing the record id as a CommandArgument to redirect to a secure page where the record can be edited or deleted.
Here's some code:
[Code]....
[Code]....
ctdRdr(0) evaluates to the ID value for the the record. )
When I click on the 'Delete' ImageButton the URL in the Response.Redirect becomes:
ctdirectory_secure/deletemember.aspx?id=<%@%20ctdRdr(0)%>
instead of, say:
ctdirectory_secure/deletemember.aspx?id=435
I'm assuming that a <%= expression %> cannot be used to set a control parameter, but how else can I do it?
View 5 Replies
Mar 5, 2010
I have a gridview with multiple rows, each has a Update button and I need to pass 2 values when someone clicks on Update button. Aside from packing the arguments inside CommandArgument separated by commas (archaic and not elegant), how would I pass more than one argument?
<asp:LinkButton ID="UpdateButton" runat="server" CommandName="UpdateRow" CommandArgument="arg_value" Text="Update and Insert" OnCommand="CommandButton_Click" ></asp:LinkButton>
As a note, the values can't be retrieved from any controls on the page, so don't offer any design solutions. Please concentrate on the question asked.
View 2 Replies
Apr 27, 2016
I have 5 textboxes in my webpage for entering address, i.e,
door no, village, city, district, pincode.
These are concatenated by comma (,) and stored into the database field address. at the time of retrieving, the concatenated address, should be separated and assign to each textboxes.
View 1 Replies
Mar 18, 2011
I wanted to know if we can pass values from Parent page (in this case from Default.aspx page) to the user control and maintain those values on subsequent "Add/Load" of user control.
So in short, if I click the "Add" button it loads my "webusercontrol" and also I am able to pass my default.aspx dropdownlist value to this dynamically loaded user control and assign it to a "Label or Textbox" which resides in my "webusercontrol", now the problem is that the value doesn't persists! What I meant is , when I click "Add" button again the "webusercontrol" gets loaded again perfectly but now all my "Label's" in webusercontrol has the new selected value from the default.aspx dropdownlist.
So say for instance I have a Dropdownlist in Default.aspx page with Values "Apple, BlackBerry, Nokia" and initial value to be passed is "Apple", I click the "Add" button, now my "Label" inside webusercontrol has the value "Apple", perfect! Next when I click "Add" button again and select a different value to be passed this time say "BlackBerry" now I have 2 webusercontrol loaded on the page, so that means I have 2 "Labels" with different ID's, but now my first Label initially had the value "Apple" because that's what I had passed and now when I passed the value "Blackberry" both the labels of my webusercontrol has the value "BlackBerry" instead of one being "Apple" and another "BlackBerry"
Is there a way to resolve this issue? may be Dictionary List?
View 3 Replies
Jun 17, 2010
I have a web page that contains a GridView which the user is allowed to "Edit", "Delete" and "Select" rows. What I'm trying to accomplish is when a user clicks on "Edit", they are redirected to another web page that contains a DetailsView of the record they selected from the GridView (previous page). How do I make the association?
View 7 Replies
Oct 5, 2010
[Code]....
How can i get the selected item in de dropdown menu in form one, ofter the button submit in the form two is clicked?
View 5 Replies
Mar 17, 2010
To pass a textbox value across a page I'm using a property on page1.aspx to pass to page2.aspx which I read using a virtual path. the code
[Code]....
When I fire a postback on page2.aspx, the content of employeeid is 0?
both code above is nested with a If Page.IsPostBack =
False
Then statement
View 4 Replies
Jun 5, 2010
I need to pass a dollar amount from one webpageto another webpage without letting the user modify the values when the values are passed between these pages. ie Page 1 (entry page) to Page 2 (confirmation page)
View 2 Replies
Apr 7, 2010
i need to pass a long list of Ids from one page to another, i was thinking of using querystring but taking in consideration that the number of ids to be passed may reach 300 i think is not a good idea.an option from my understanding may be the use of session, this seems to me an optimal solution in my case but on the other hand I can certainly clear the session when the user performs a certain action and the list of ids is not longer needed, but if the user leaves the page without performing any action i want to clear the session, how can i do it?f multiple users are using the same functionality do i need the session's items to be confused or the session is for a single user?
View 4 Replies
Feb 22, 2010
i want to pass values between forms. wat i did is, I have textbox, a button in form 1 and a label in form 2
1. Created a property to return text of textbox in form 1
2. in form 2 i added previouspagetype and virtual address then i tired to access the property (label.text = previouspage.propertyname).. but no success..
i tried to loop through all controls in previous page to get the value but still its not working.. i wan a simple way.. without using sessions, cookies or anything..
View 19 Replies
Feb 28, 2010
here i have a problem,i need to pass the value of one tab to another for tab. For example if i selected a row in the DataGrid based on the DataKeyField of that row i have to display the details in the second tab panel. i tried it but getting a error.
View 2 Replies
Nov 12, 2010
I am creating a DataSet to attach to a report (*.rdlc). In the DataSet is a TableAdapter that has the GetData(@start, @end) function. Can someone please explain how I get values in to @start and @end? I have searched and seen that it might have something to do with overriding the Fill function in the DataSet code behind file. Please let me know.
View 1 Replies
Jan 30, 2010
I am building a webpage and getting the values entered in textbox from the use now I want to use the values on the next page and want to display the values overthere... I'll explain in detail:
I have a form like below:
Now I want to redirect the user to another page on button click and then use the values of this textbox.
View 11 Replies
Nov 1, 2010
I have an ASP.NET Image control declared as:
<asp:Image runat="server" ID="SortOrder"
AlternateText="Ascending"
ImageUrl="~/images/sort_ascending.gif"
CssClass="Ascending"
EnableViewState="true"
/>
[code]...
View 2 Replies
Jul 6, 2010
i am using a list view for viewing some information to user there i used a hyperlink in each row to show detailed information in a modal popup in the same page what i want on the click of particular hyperlink the detailed report of that row only should display.
[ID] is the primary key in my database iam passing that as an object from aspx file to the code behind and using that id to fetch data from database. but each time it is showing same information.
View 1 Replies
Oct 29, 2010
I need to auto-redirect a page depending on the a ID number in the address bar. When I run this code, It is giving following exception
string temp = Request.Url.ToString();
string subTemp = temp.Substring(temp.IndexOf("ID="));
temp = subTemp.Remove(subTemp.IndexOf("&"));
subTemp = temp.Substring((temp.IndexOf("=") + 1));
Response.Redirect("http://Share1/ncr/Default.aspx?ID=" + subTemp);
Server Error in '/' Application.
StartIndex cannot be less than zero.
Parameter name: startIndex
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: StartIndex cannot be less than zero.
Parameter name: startIndex
Source Error:
[Code]....
Stack Trace:
[Code]....
[ArgumentOutOfRangeException: StartIndex cannot be less than zero.Parameter name: startIndex] System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +7494975 TestCodeBehind2.Class4.Page_Load(Object sender, EventArgs e) +69 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
View 3 Replies
Mar 15, 2011
I am trying to pass some text values from one page to another and I am having some issues. When I click on one button in the parent page then it opens a new popup windows and the user introduce a value in a textbox and when the user click on other button in the popup page, it sould pass some text values to the parent page (puts it in a textbox). The problem is that I have to click twice on the button from the popup window to pass that values, the first time I click the button It shows an error message but the second time I click on it every thing works ok.
[Code]....
View 5 Replies
Mar 2, 2011
I am using the silverlight application for in my project,i have problem with passing values from silverlight application to asp.net web application page. so how to pass the values from silverlight to webapplication.
View 2 Replies
Feb 8, 2011
i have to pass a value in the textbox in one application to another one in run time. Two web application resides in the same Solution. how can i do it?
View 9 Replies
May 14, 2010
I'm only a newcomer to ASP.NET MVC and am not sure how to achieve a certain task the "right way".
Essentially, I store the logged in userId in HttpContext.User.Identity and have written an EnhancedAuthorizeAttribute to perform some custom authorization.
In the overriden OnAuthorization method, my domain model hits the database to ensure the current user id can access the passed in routeValue "BatchCode". The prototype is:
ReviewGroup GetReviewGroupFromBatchCode(string batchCode);
It will return null if the user can't access the ReviewGroup and the OnAuthorization then denies access.
Now, I know the decorated action method will only get executed if OnAuthorization passes, but I don't want to hit the database a second time to get the ReviewGroup again.
I am thinking of storing the ReviewGroup in HttpContext.Items["reviewGroup"] and accessing this from the controller at the moment.
View 3 Replies
Sep 6, 2010
I usually use STATIC implementation when developing Desktop Application and I just got my head bumped on the wall when I use STATIC in ASP.NET (not a good idea)I think I saw some feedback here before that you can use INTERFACE for passing values between Classes and Pages without using Session.here's my sample code
public interface ISessionManager
{
SessionStates sesState { get; set; }[code]....
View 2 Replies
May 7, 2010
Code:
SELECT one, two, three, four FROM tblFixedLine_onenet_callLog WHERE (one LIKE '%' + ISNULL(@one,'') + '%') AND (two LIKE '%' + ISNULL(@two, '') + '%') AND (three LIKE '%' + ISNULL(@three, '') + '%') AND (four LIKE '%' + ISNULL(@four, '') + '%') ORDER BY one, two, three, four
@one, @two, @three and @four are textboxes on my ASP.NET page all of which by default have no value(therefore i assumed NULL).If i test the SQL in the VS2005 SQL Configuration (and put the values in manually) it works but the ASP page returns no results... i assume therefore the Textbox value is "" not Null.
View 13 Replies
Feb 2, 2010
How to send values from page1 to page2 in ASP.NET,
View 6 Replies
Jan 20, 2010
I'm having problems passing values from the controller to the view. I created a boolean variable to use as a flag and want the view to render some html based on whether its true or false.
Unfortunately ViewData doesn't look like it can pass boolean values. I should be able to pass any datatype to a view (string, int, bool, etc...)
View 16 Replies