How To Loop The Server Controls And Clearing Values
Jan 4, 2010
I have some server controls both textboxes and drop down list box's that I placed on a panel control. My question is I would like to loop through the controls textboxes and drop down list and clear all values.
Here is my code, using LinQ to get the data from database.
public IEnumerable categoryData() { db = new DBModelDataContext(); var cat = from c in db.Categories select new { c.categoryname,c.categoryid }; return cat; }
trying to get the values (categoryname and categoryid) into textfiled and valuefield of dropdown list.
dt = new clsData(); ddlCategory.DataSource = dt.categoryData();
what is the code that i need to write to assign the categoryname to textfield and categoryid to valuefield. I mean how to loop through the values coming from the above function.
select AutoIdx,TxDate,Id,AccountLink,Description,Debit,Credit,(Debit-Credit) as Actual from PostGL where Id='JL' and AccountLink=2
AutoIdx TxDate Id AccountLink Description Debit Credit Actual 3 2010-01-22 JL 2 bcb 0 35.09 -35.09 5 2010-01-28 JL 2 g 3.51 0 3.51
I am trying in view like this
declare @cnt int declare @i int set @budget=20 set @cnt= (select COUNT(*) from PostGL where AccountLink=2 ) set @i=1 WHILE (@i<=@cnt ) BEGIN set @tdebit=??
END
I am taking count the no of rows having AccountLink=2 I need to read all debit,credit and add all debit into totaldebit,all credit into totalcredit independently from table. then i need to show the totaldiff as Actual. i need ....totaldiff=totaldebit-totalcredit
I am dealing with dynamic fields in a for loop and now I need to retrieve the values that are being typed in the dynamic fields, any idea how can I do that? 2)also when I click the submit button, upon postback, the dynamic fields have gone missing, have been trying to slove that, but i did not, anyone knows how to deal with this? kinda urgent :x
3) and How do you compare the 2 dynamic fields? For eg: Im comparing the tbSch[i] to tbSch[i], so that the dates cannot be the same, am using a compare validator, but it throws me error that im comparing the same fields :) even though i change to ("tbSch" + i) for both, sorry Will provide my code snippet as follow :D tbNum is a textbox where user enter numbers and click generate
protected void btnGen_Click(object sender, EventArgs e) { for (int i = 0; i < Convert.ToInt32(tbNum.Text); i++) { // label and textbox needed Label lblSch = new Label(); TextBox tbSch = new TextBox(); Label lblWsGrp = new Label(); DropDownList ddlWsGrp = new DropDownList(); CompareValidator cvSame = new CompareValidator(); cvSame.ID = "cvSame" + i; cvSame.ErrorMessage = "Date cannot be the same"; cvSame.Operator = ValidationCompareOperator.NotEqual; cvSame.Type = ValidationDataType.Date; cvSame.Display = ValidatorDisplay.Dynamic; cvSame.EnableViewState = true; cvSame.ControlToValidate = (tbSch.ID);<<<<< what should be the value in here? cvSame.ControlToCompare = (tbSch.ID);<<<<<<<<<< and here? //schdule date lblSch.ID = "lblSch" + i; lblSch.Text = "Session Date : "; lblSch.EnableViewState = true; tbSch.ID = "tbSch" + i; tbSch.Width = 210; tbSch.Height = 27; tbSch.EnableViewState = true; //workshop grp lblWsGrp.ID = "lblwsgrp" + i; lblWsGrp.Text = "Workshop Group : "; lblWsGrp.EnableViewState = true; ddlWsGrp.ID = "ddlWsGrp" + i; ddlWsGrp.Height = 27; ddlWsGrp.Width = 210; ddlWsGrp.EnableViewState = true; ddlWsGrp.Items.Add("1"); ddlWsGrp.Items.Add("2"); //table to store data TableRow trow = new TableRow(); TableRow trow2 = new TableRow(); //row1 TableCell tc1 = new TableCell(); TableCell tc2 = new TableCell(); TableCell tc3 = new TableCell(); TableCell tc4 = new TableCell(); //row2 TableCell tc5 = new TableCell(); TableCell tc6 = new TableCell(); TableCell tc7 = new TableCell(); TableCell tc8 = new TableCell(); TableCelltc9 = new TableCell(); tc1.Controls.Add(lblSch); tc2.Controls.Add(tbSch); tc3.Controls.Add(lblWsGrp); tc4.Controls.Add(ddlWsGrp); tc5.Controls.Add(space); tc6.Controls.Add(CeSess); tc7.Controls.Add(space); tc8.Controls.Add(space); tc9.Controls.Add(cvSame) trow.Cells.Add(tc1); trow.Cells.Add(tc2); trow.Cells.Add(tc3); trow.Cells.Add(tc4); trow2.Cells.Add(tc5); trow2.Cells.Add(tc6); trow2.Cells.Add(tc7); trow2.Cells.Add(tc8); trow2.Cells.Add(t9); this.table3.Rows.Add(trow); this.table3.Rows.Add(trow2); } }
I would like to ask a question on the visual basic codes to loop the gridview to retrieve the values and based on the values, it will be provided as parameters to update to the database table using stored procedure.
Firstly, I have a gridview named grvProduct. The page (ui) will be loaded with data from the database with the use of stored procedures. And only certain values can be edited through the use of template in gridview. So based on those edited values, I'm supposed to pass these values as parameters to the stored procedure which will then update a database table.
Let say, I have 3 records retrieved from the database and displayed in the gridview. And I would like to edit a values in the 3 records, how do I do batch update and pass those parameters to the stored procedure? I went to debug and step through the visual basic codes and realised there were too many arguments specified because I actually loop the gridview.
Below is my visual basic codes:
[Code]....
Below is my Stored Procedure code: [Code]....
I believe it is the error in the looping of the gridview which results that I could not batch update the data/values.
I have some files listed on a listbox and want to upload them to the server. The values doesn't need to be selected. But I can't even get it working. Below is my source code:
This way buttons are rendered on design view as well. The problem is that number of buttons to render is dynamic based on data in xml file (even if the data was static, the number of button is about 12 and I don't think it is wise to copy paste the same code above 6 times...). I thought by using loop for that:
int i = 1; foreach (Button button in tb.Items) { writer.AddAttribute(HtmlTextWriterAttribute.Type, "button"); writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo" + i); writer.AddAttribute(HtmlTextWriterAttribute.Value, button.ButtonValue); writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.RenderEndTag(); //button i++; }
tb is defined in OnLoad; On run time it works, but on design time I get error: > Error rendering control. And control is not being rendered.
Is it possible to add the ListItem values in the code-behind within a for loop? If so, what is it? Here is my current code:
rblContentTypesGetAll.Items.Clear(); for (int i = 0; i < dt.Rows.Count; i++) { rblContentTypesGetAll.Items.Add(dt.Rows[i]["contentType"].ToString()); }
I have always had problems with creating loops so here I go again.
I have a dataset populated with 1 column and multiple rows. What I am trying to do is create a page that will be used for emailing multiple users. The names will need to be separated by a semi colon.
Actuall i retrive one row from Database with more than 80 columns on page load. Now i need to fill these data in every control like Text-Box and Combo-Box which i have using on the Page.
My Column Name and My Id of the Textbox or combobox are same. now i need to fill the value in textbox and combobox where coumn name and textbox id are same.
Eg.
(1) TextBox Id's Name :- txtCustName, txtCustNo, txtAddress, etc(More than 80 Column).
now i will be remove the 'txt" from every id.
so it would be seems like CustName, CustNo, Address, etc.
I am currently building a web site and I utilize cascading drop down lists. I am having difficulty clearing two of my drop downs. The application is utilizing Visual Basis. Here is what I found through my research but they are not resetting my drop downs after a post back:
I've been trying to build a toolbar for a web form that does some user management stuff. The toolbar works as expected, except, when you postback the page, any LinkButton controls that are more complex than standard text controls, for some reason they have their controls cleared on post-back. If I remove the JavaScript attribute from the link button, the controls postback fine without issue, but I need the JavaScript attached to the button to do some other stuff before postback. If I move the attribute addition in the code-behind to the OnClientClick property of the lnkbFindUser control, this control doesn't lose the child controls, but lnkbSave does. Attached is a sample page that demonstrates the problem. If you click the Find user button, it'll postback and clear the Find user button. If you click Save, it'll clear it as well. When you attach the debugger to the lnkbFindUser loading events, you can see that all the controls are properly attached during Init, but they're dropped before Load. How do I stop this from happening? I don't want to have to drop all the icons next to the buttons, but I'm beginning to think this is the only way I'm going to get it to work.
hope somebody can help with this issue as I've been struggling for days to work out what I've done wrong. Basically, I have a gridview that I've attached a small pop-up form to edit just the fields that I want editing (rather than all of the fields from the GridView). The update works OK in that the data is written back to the database OK and the pop-up form closes. However, the view of the gridview isn't returned and everything is as though the pop-up form was still there. The only way around it seems to refresh the page. The front-end is like this:
I am designing a web page that allows for the maintenance of a single table - so I have some controls that allow the user to specify some search parameters, a button that then populates a gridview with the result of the search meeting the search parameters, and a details view for inserting and updating specific records. The gridview and detailsview are bound to appropriate sql data sources.All pretty standard.There is also a "reset" button that clears the results of the current search - sets the visibility of the gridview and detailsview to false, and clears the search parameters. Again, pretty standard.What I have done is when the user goes to insert a new record, the gridview and search parameter specification controls are hidden, and the details view displayed. If they cancel the insert operation, the details view is hidden, and the search parms and gridview displayed - but what I am finding is that there are situations when a previously populated gridview is displayed. Here's the situation:1) Specify some search parameters, click search - and the gridview appears, with the appropriate records displayed.
2) Click on the clear button (oops - I didn't want to search, but add a new record). The gridview disappears, the search values are cleared out.3) Click on the insert button - the detailsview opens in "insert" mode.So far, this all works well, and is intuitave to the users.4) Click on the "cancel" button on the details view. I hide the details view, and show the gridview and search parameters. The gridview appears - with the results of the previous databinding still in it.My question is: Is there an easy way to "unbind" the gridview? From my understanding of how the datasource to gridview (or detailsview) connection is done, there is a datatable "behind the scenes" that manages the two way data binding. I also assume that data that has been bound to a gridview is carried over in the viewstate - it would be nice to clear out unneeded data in that.
I have a gridview which at run-time contains X number of records. Upon clicking a DELETE linkbutton on a particular row the gridview completely disappears from the page, when it should reflect simply the loss of that one record. Everything is okay on the database end, the record is deleted, so I know that part is working. I run a query and rebind the gridview within the Rowdeleted event. I even try hardcoded a value in the query which I know exists in the database and it still doesn't refresh with this record showing. Whatever code I need to post, let me know.
I am using multiple threads in my .net web application. Certain functions may need to execute at any arbitrary time. However, I do not need these (and the entire application) to be fully asynchronous, as there is an acceptable tolerance in this execution time. Here is a rough example of what I need to do:
main() { loop { if (flagA) then doTaskA(); if (flagB) then doTaskB(); } }
...where flagA and flagB are set via asynchronous timers in critical section. The actual execution of the requested tasks would thereafter run in series.
This is very easy to do in C/C++, etc. But I cannot find any access to such control in .NET, specifically in the web server/application architecture. It may be that it doesn't exist; however, I am assuming that the server must do something of this sort as it manages applications. I would like to hook into that somehow; even if via some application function that is called regularly during this loop.
I have written SP like this to get my required output.create procedure [dbo].[usp_gl_ProjectBudgets] set nocount on begin tran declare @SPError int
declare @y1 varchar(20) declare @y2 varchar(20) declare @y3 varchar(20) declare @y4 varchar(20) declare @y5 varchar(20) declare @Glink int declare @i int set @y1='Year1' set @y2='Year2' set @y3='Year3' set @y4='Year4' set @y5='Year5' set @Glink=1 set @i=1 [code]...