C# - Creating Strings Inside A For Each Loop? Or Creat Them Outside, Use Inside?

Dec 10, 2010

i have the following code below and was lookign to clean it up, but am not sure if it needs clean up or not.

foreach (SearchResult sr in mySrchColl)
{
string strValIn = sr.Properties["in"][0].ToString();
string strValOut= sr.Properties["out"][0].ToString();
}

do i change this to something like this:

string strValIn = "";
string strValOut= "";
foreach (SearchResult sr in mySrchColl)

[code]...

whats the difference or are these two identical?

View 6 Replies


Similar Messages:

How To Increment Anchor Tag Id Inside For Loop

Mar 25, 2011

how to increment anchor tag id inside for loop.

View 4 Replies

MVC :: Ajax.beginform Inside A For Loop?

Oct 2, 2010

so I am using a foreach loop to iterate through comments. The comment section is wrapped inside "Comments" div. My function **DeleteComment** fetches comments again once you delete a comment and rebinds it to the control. However, after you delete a comment, anytime you try to delete another comment, the commentId of the very first deleted comment would keep getting passed to **DeleteComment** function instead of the passing the commentId of the comment you are trying to delete. If you refresh the page, then you can delete ONE comment again, and the same problem if you try to delete another.

View 1 Replies

Threads Inside A Foreach Loop In C#?

Jan 5, 2010

I had the following code to send different mails to differnt users in my asp.net web application

foreach (DataRow dataRow in dataTable.Rows)
{
sendMails();

[code]...

View 8 Replies

Web Forms :: Loop Inside Try - Catch Block?

Apr 29, 2010

Can somebody show me a better approach of looping through a Try -Catch statement. I have something like this:

Try
dbConn.Open()
Catch ex As Exception
errmsg = ex.Message
End Try

I need to try to connect 5 times before logging an error. My first thought was to nest Try - Catch 5 levels but I didn't like that idea. I'm sure there is better solution to it.

View 6 Replies

Is Possible To Set Control Properties Inside A Loop Without CodeBehind

Jan 11, 2011

Is it possible to set properties of an control inside a loop without using code behind? For example how can I set the Text property of the LinkButton inside the following loop at runtime, color being a POCO?

<table>
<%foreach (var color in GetColors()) {%>
<tr>
<td><asp:LinkButton runat="server" Text='<%# ??color.MyProperty?? %>' /></td>
</tr>
<%}%>
</table>

View 1 Replies

Using Array Of Asp Inside Javascript Is Not Working In The Loop?

Mar 12, 2010

I have a problem that when i bring the array of asp and use it in the javascript, When i use the counter (i++) and print for each index of array just like "<%=app[i] %>" and it is not return the value back to me.i solve this problem for a dayedit

<%
String[] asp = {"a","b","c"};
%>

[code]...

View 1 Replies

C# - Static Vs Member Field Revisited / Want To Persist A Large Dictionary Of Strings Inside The Memory?

Feb 18, 2011

I need an advice on piece of functionality that I am ought to implement. The scenario is that we haven an HttpHandler which servers to intercept file uploads. In the handler, I need to persist a large dictionary of strings inside the memory. The dictionary might be as large as 100 entries. I am wondering whether it is safe to store that in a static variable, so that it is not initialized every time instance of the handler is created (there will be a lot of instance for sure). In general, what is the approach in such scenarios. Is it a generally better idea to use static fields, to persist data that will not be changed?

View 5 Replies

C# - Accessing Checkbox Inside Html Table Loop From Code Behind?

Feb 8, 2011

I have a question about asp.net

I have this table with checkbox for each row:

[URL]

table code inside the ASPX page:

[URL]

So I'm trying to implement the delete selected button.. How exactly do i point to the specific checkbox for a particular row from codebehind when all 3 have the same name chkSelected? I know how to do it with a gridview, but not quite sure how if we do it with a for loop..

Can I do something like this inside btnDelete_Click?

[Code]....

View 1 Replies

Forms Data Controls :: Display Each Value Inside A 'for' Loop In Gridview?

Jul 15, 2010

I have a code like yis

for(int i=0;i<Count;i++)
{

k=item(i);
}

I want to add each value of 'k' to a gridview..If I have 10 values for 'k' (count=10), then I want to display a gridview with 10 rows...How can I do this?..

View 4 Replies

Data Controls :: For Loop Inside Gridview Row Databound Not Working?

Mar 1, 2014

This is my for loop code, it is working fine , just the problem is, if there are 10 rows , it runs for 9 rows and not for 10th time? What correction is needed?

protected void gvouter_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int count_rows_for_saving_answers = gvouter.Rows.Count;
for (int ii = 0; ii <= count_rows_for_saving_answers - 1; ii++)
{
Label lblsubid = (Label)gvouter.Rows[ii].FindControl("lblsubid");

[Code].....

View 1 Replies

Databases :: MySql Transaction Inside A Loop - Delete A Bunch Of Records

Sep 30, 2010

I'm trying to delete a bunch of records in mysql. The record info to delete (userid, name) is stored in an arraylist. It seems to only delete the first record and gives an error ("Transaction has already been rolled back or is not pending.") afterwards. I have the transaction commit inside the loop which I think is the issue but not sure how to go further if I bring it outside of the loop. Here's the relevant bits of the code.

try
{
ArrayList alist = new ArrayList();
//alist gets populated with data like (12345,robot)(23456,car) here.
MySqlConnection conn2 = new MySqlConnection(query_connection);
conn2.Open();
MySqlCommand command2 = conn2.CreateCommand();
MySqlTransaction mytransaction;
mytransaction = conn2.BeginTransaction();
command2.Transaction = mytransaction;
for (int i = 0; i < alist.Count; i++)
{
string[] s = alist[i].ToString().Split(',');
try
{
command2.CommandText = "DELETE from users_settings WHERE UserID=" + s[0].ToString();
command2.ExecuteNonQuery();
command2.CommandText = "DELETE from users WHERE ID=" + s[0].ToString();
command2.ExecuteNonQuery();
mytransaction.Commit();
}
catch (Exception e){
mytransaction.Rollback();
}
}
}
catch(Exception e){
}

View 1 Replies

Forms Data Controls :: Javascript Loop Through Each DropDownList Inside GridView

Mar 28, 2010

I have a GridView, the first column it's a RadioButton template and the second it's a DropDownList Template, the number of rows depends on the user, I mean they are not static. I'm using the following JS function to get the row selected with the radiobuttons:

[Code]....

With this function I know which RadioButton was selected, now, I would like to get the DropDownList value or text of the selected row, I know I have to loop through every DropDownList to get an array of controls, but since they are something like ctl00_ContentPlaceHolder1_GVProducts_ctl02_DValsDropDown, I just don't know how to achive this through JS.

View 3 Replies

Forms Data Controls :: Check Inside Loop Statement If One Of The Textboxes Has The Same Value

Jan 13, 2011

In my application I have panel which has 5 textboxes. I've written several functions for checking each of textbox if the entered value is ok (number, is this number in database, etc.). If error occurrs textbox which caused it has different color of background.

However I wanted to write (add) function which will check if one of the textboxes has the same value as other. The problem is that function is checking blank textboxes, although it shouldn't - I wrote if statement which allows checking only non-blank textboxes but it doesn't work.

View 22 Replies

C# - Creating Web Controls Inside A Content Placeholder Programmatically?

Mar 31, 2011

I've got a master page and a content page. How can I add controls to the master page's content placeholders programattically?

View 2 Replies

Web Forms :: Creating / Opening Tabs Dynamically Inside CSS?

Jan 1, 2010

I'm trying to create new tabs within page. When I click a link in my navmenu, it should open the Redirected page in a new tab within the page as new tab (not the browser tab). It is something like the visual studio, where we get the page opened inside a new tab when you click an item in the Solution explorer. Would any body let me know how to implement this functionality. (generate tab with close functinality). I m not talking about TabStrip.

View 4 Replies

Custom Server Controls :: Rendering Controls Via Loop Inside Render

Nov 11, 2010

I am creatin a server control where some controls are being rendered inside `protected override void Render(HtmlTextWriter writer)`

writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo1");
writer.AddAttribute(HtmlTextWriterAttribute.Value, "Button1");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag(); //button
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo2");
writer.AddAttribute(HtmlTextWriterAttribute.Value, "Button2");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag(); //button

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.

View 1 Replies

C# - Creating Instances Of A Class Inside A Static PageMethod Thread Safe?

Dec 14, 2010

I am using jQuery to call PageMethods. For certain operations, the current user credentials must be validated and for other operations, I need to call other static methods. Here is some sample code:

Sample #1

[WebMethod]
public static void PostComment(string comment)
{
UserAuth auth = new UserAuth();
if (auth.isAuthenticated)
{
//Post comment here...
}
}

Sample #2

[WebMethod]
public static string GetComment(int commentId)
{
commentDto comment = //get comment data from the database...
string friendlyDate = ConvertFriendlyDate(comment.commentDate);
return friendlyDate + " " + comment.text;
}
public static string ConvertFriendlyDate(DateTime commentDate)
{
string friendlyDate = //call static utility method to convert date to friendly format
return friendlyDate;
}

Will I be safe using these kinds of operations? Am I better to drop page methods and just call a separate ASPX page for my AJAX requests?

View 4 Replies

C# - Creating Server Controls Dynamically At Runtime Inside A Grid Item Template?

Aug 6, 2010

I've an item template inside a grid which has a <asp:LinkButton/> inside it. I assign the text for the link button as

<%# Convert.ToString(Eval("Tags"))%>

Tags can have a string with multiple tags in it delimited by space. For eg. "sports", "sports cricket", "sports cricket sachin" are the examples of some possible tags.

I want to create a button for each tag inside the string. How can i create the controls (server control - linkbutton) dynamically during runtime inside the grid item template?

View 2 Replies

ADO.NET :: How To Add Column To DataTable Inside Loop Then Sort On New Column

Mar 22, 2011

I am grabbing an XML feed an throwing it into a dataset. I am looping through the datatable that is in the dataset and adding a column to the datatable (Distance) that is the result of a calculation. What I then need to do is sort the dataset on the new column (Distance) I added, but it is not working... Here is a sample of my code.

[Code]....

View 1 Replies

Forms Data Controls :: Creating A Click Event Handler On A Linkbutton Inside A Templatefield

Feb 16, 2011

I would like to call a method and pass a value to it on a link button autogenerated from the database in a templatefield inside a datagrid. I don't know much about delegates

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
..
((LinkButton)e.Row.Cells[(int)eMessage.TitleColumn].FindControl("btnMessageTitle")).Click += new EventHandler(delegate { viewSelectedMessage(this, 35); });
}
void viewSelectedMessage(object sender, int messageID)
{
lblTest.Text = messageID;
}

running the website and viewing the page source, I have realised that there is an OnClick event created for the linkbutton, however, this may be generated anyways. By running my solution using VS debugging, I can see that my method won't fire by clicking any of thos generated linkbuttons.

View 3 Replies

Forms Data Controls :: Populating DropDownList Inside A ListView Inside A FormView

Jan 16, 2010

I have the following (abbreviated) code:

<asp:FormView ID="FormView1" runat="server" DataKeyNames="ItemID" DataSourceID="LinqDataSource1">
<EditItemTemplate>
<asp:DropDownList ID="ddlCategory" runat="server" SelectedValue='<%# Eval("Category") %>'
DataSource="<%# GetCategories() %>" DataTextField="Text" DataValueField="Value" />
</EditItemTemplate>
<ItemTemplate>
<asp:ListView ID="lvParticipants" runat="server" DataSource='<%# Eval("Participants") %>' >
<InsertItemTemplate>
<asp:DropDownList ID="ddlCountry" runat="server" SelectedValue='<%# Eval("Country") %>'
DataSource="<%# GetCountries() %>" DataTextField="Text" DataValueField="Value" />
</InsertItemTemplate>
</asp:ListView>
<ItemTemplate>
</asp:FormView>

When the FormView is in Edit mode, ddlCategory is populated as expected by calling GetCategories(), which returns a List of categories. However, when the ListView is in Insert mode, ddlCountry is empty. I put a break point in GetCountries(), but it never gets called. If I change the name of the method, I get an error. So it recognizes the method at compile time, but does not call it at run time. I'm guessing this is an embedded binding issue of some kind, but I'm hoping someone can save me a lot of time by pointing out the solution.

View 11 Replies

Forms Data Controls :: Locate Autocompleteextender Inside Of Listview Inside Of Tabcontainer

Jan 25, 2010

I am loading the autocomplete extender properly but I need the PK from the selectedValue. I have looked at other examples and they do NOT show how to drill into the tabcontainer, then drill into the listview, and then locate the extender value. Here is what I have so far. My "TABCONTAINER" value shows the extender correctly but I am unable to locate it.

[Code]....

View 2 Replies

State Management :: Update Panel Inside User Control Inside Modalpopupextender?

Apr 9, 2010

I've created a multiple uploadfile user control - upload_multiple_files.ascx:

[Code]....

which has an update panel ID = up_upload_multiple_files this user control will be placed inside a modalpopupextender. My question is when I click in any button AddFile, RemvFile, Upload there's a postback so the page is reloaded and the modalpopupextender disapears Is there a way to to troubleshoot this?

View 8 Replies

Forms Data Controls :: How To Disable Button Inside EditItemTemplate Inside DetailsView

Jan 20, 2011

I have a boolean / bit value in the database called "is_paid". Depending on this value I want to Disable a button. (the same would go for example to set a textbox not Visible, but anyway)

What I want is to Disable the button, if my boolean is 1 (true).

First I tried to convert my boolean value to text:

<asp:Button
ID="btnCalculatePayment"
runat="server"
Text="Submit"
onclick="btnCalculatePayment_Click" Enabled='<%#
Convert.ToBoolean(Eval("is_paid")) ? "False" : "True" %>'
/>

But got an error:

CS0030: Cannot convert type 'string' to 'bool'
However, if I use it one a Label it works fine: <asp:Label
ID="lblIsPaid"
runat="server"
Text='<%#
Convert.ToBoolean(Eval("is_paid")) ? "True" : "False" %>'></asp:Label>

So another trial I did was to CAST the data from the database to be the text that I want, like so:

SELECT not_paid = CASE WHEN is_paid = 0 THEN 'True' WHEN is_paid = 1 THEN 'False' END ....

And my code changed to:

<asp:Button
ID="btnCalculatePayment"
runat="server"
Text="Submit"
onclick="btnCalculatePayment_Click" Enabled='<%#
Bind("not_paid") %>'
/>

But got this error:

System.InvalidCastException was unhandled by user code
Message=Specified cast is not valid.
Source=App_Web_absjd3ob
StackTrace:
at ASP.manager_aspx.__DataBinding__control74(Object sender, EventArgs e) in c:Documents and SettingsAdminMy DocumentsVisual Studio 2010ProjectsWebManager.aspx:line 219
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()

So I wonder, is it possible to change the "Enabled" property based on by boolean value?

View 6 Replies







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