String Builder Versus Repeater (which Is Best)
Jun 29, 2010I have written such a code to loop through the records and build a string.
Is this s good idea or should I use repeater or something?
[code]....
I have written such a code to loop through the records and build a string.
Is this s good idea or should I use repeater or something?
[code]....
what string builder command do in the asp.net cs file.
View 4 RepliesI am using the code below (simplified for this example) to post data to a SharePoint list
StringBuilder customerDoc = new StringBuilder();
customerDoc.Append("<Method ID='1' Cmd='New'>");
customerDoc.Append("<Field Name='Name'>" + Name + "</Field>");
customerDoc.Append("<Field Name='Age'>" + age + "</Field>");
customerDoc.Append("<Field Name='City'>" + city + "</Field>");
customerDoc.Append("<Field Name='Country'>" + country + "</Field>");
customerDoc.Append("</Method>");
XmlDocument xDoc = new XmlDocument();
XmlElement xBatch = xDoc.CreateElement("Batch");
xBatch.SetAttribute("OnError", "Continue");
xBatch.InnerXml = sb_method.ToString();
XmlNode xn_return = sharePoint.listsObj.UpdateListItems(ConfigurationManager.AppSettings["SaveCustomer"].ToString(), xBatch);
As you can see I am using a stringbuilder which isn't ideal so I wonder what I should use instead to create an XML string?
SqlDataReader myreader;
myreader = cmmd.ExecuteReader();
StringBuilder sb = new StringBuilder();
sb.Append("<b>Vaccine</b> <b> Vaccination Date</b> <b> Vaccination Due Date</b> <b> Incomplete Vaccination </b> <b>Dose No.</b> <b> Remarks </b><br/><br/>");
while (myreader.Read())
{
sb.Append(myreader["VaccineID"]);
sb.Append(" ");
sb.Append(myreader["DateOFVaccine"]);
sb.Append(" ");
sb.Append(myreader["NextVaccinationDueDate"]);
sb.Append(" ");
sb.Append(myreader["AnyIncompleteImmunization"]);
sb.Append(" ");
sb.Append(myreader["DoseNumber"]);
sb.Append(" ");
sb.Append(myreader["Remark1"]);
sb.Append("<br/>");
}
lblDisplayDetails.Text = sb.ToString();
myreader.Close();
WHAT EXACTLY I WANT IS TO RETRIEVE DATA(may be from separate table) AND THEN DISPLAY THEM PUTTING SOME STYLE(font,color etc). Is retrieving from multiple table is possible in gridview ? I could use the DataReader, but how to display them in style(font,color etc)?
can i add string builder object to a dictionary object? If yes code it. I mean i have a dictionary in which i have already added a few (string, objects), and i have a string Builder which has few variable already added now i want that instead of passing 2 different object in a method i want to pass only one object so can i add string builder object to same method as well
View 2 Repliesstring url = "~/sales/saleimage/RedErrorImage.png";
StringBuilder b = new StringBuilder();
b.Append("<img src=");
b.Append(url);
b.Append("alt='No Image Available' width='350px' height='200px' >");
Image not Displaying where m i wrong
I am having doubt in whether to use string or string builder to append html elements like "div" and others in my page in mvc. Is there any other approach for this thing.
View 7 RepliesStringBuilder displayList = new StringBuilder();
I have added a few items in displayList but in my code i need to search for an item in displayList how can i search an item added to displayList.
i am using stringbuilder but i have hit a problem. the line below
sb.AppendLine("ctl00_ContentPlaceHolder1_rptNav_ctl00_AssetsTreeControl_1_pnlAssetsContext");
i need this to be passed as a string value ie
ctl00_ContentPlaceHolder1_rptNav_ctl00_AssetsTreeControl_1_pnlAssetsContext
'ctl00_ContentPlaceHolder1_rptNav_ctl00_AssetsTreeControl_1_pnlAssetsContext'
the problem is if i do this i get a js error of
Error: syntax error
Source Code:
return ShowContextMenu(event,
StringBuilder sb = new StringBuilder();
sb.AppendLine("<b Id='");
sb.AppendLine(assets_item.Id.ToString());
sb.AppendLine("' oncontextmenu='return ShowContextMenu(event, ");
sb.AppendLine("ctl00_ContentPlaceHolder1_rptNav_ctl00_AssetsTreeControl_1_pnlAssetsContext");
sb.AppendLine(")'>");
sb.AppendLine(assets_item.Title);
sb.AppendLine("</b>");
I try to use method post to pass variable to next page. I find out that i can use stringbuilder to crete html element and then have the variable i want to pass in hiddenfield and then post and redirect to second page.
execute stringbuilder immediatley after a button is click ?
My coding is as below :
[Code]....
I am new at json, I want to make jquery ajax call to a asp.net webmethod to get back simple JSON object using string builder
[WebMethod]
public static string GetmyJSON()
{
[Code]....
But My alert message showing undefined instead of Manas why, Where I am doing wrong isn't possible to return a json object using string builder ? if possible how to write it.
Suppose i am having 25 character length string and I want to bind only first 15 character of that string into the label control.
<a href="[URL]" >"<span class="name" style="text-align: left; font-family: Arial; color: #0094DA; font-size: 14pt">
<%#Eval("Name").ToString().Length >= 30 ? Eval("Name").ToString().Substring(0, 30) : Eval("Name").ToString()%></span></a>
my ASP.NET application reads an xml file to determine which environment it's currently in (e.g. local, development, production).
It checks this file every single time it opens a connection to the database, in order to know which connection string to grab from the Application Settings.
I'm entering a phase of development where efficiency is becoming a concern. I don't think it's a good idea to have to read a file on a physical disk ever single time I wish to access the database (very often).
I was considering storing the connection string in Application["ConnectionString"].
[code].....
I didn't design the application so I figure there must have been a reason for reading the xml file every time (to change settings while the application runs?) I have very little concept of the inner workings here. What are the pros and cons?
What is the difference between; Deploying an application Releasing an application Implementing an application
View 1 RepliesI've gone rounds with this ever since I started programming classic ASP 12 (or so) years ago and I've never found a great solution because the architecture of ASP and ASP.NET has always been a swamp of bad practices, magic shared singletons, etc. My biggest issue is with the HttpApplication object with its non-event events (Application_Start, Application_End, etc.).
If you want to do stuff once for the entire lifespan of an HTTP application, Application_Start is the obvious place to do it. Right? Not exactly. Firstly, this is not an event per se, it's a magic naming convention that, when followed, causes the method to be called once per AppDomain created by IIS.
Besides magic naming conventions being a horrible practice, I've started to think it might be a reason there exist no such thing as a Start event on the HttpApplication object. So I've experimented with events that do exist, such as Init. Well, this isn't really an event either, it's an overridable method, which is the next best thing.
It seems that the Init() method is called for every instantiation of an HttpApplication object, which happens a lot more than once per AppDomain. This means that I might as just put my startup logic inside the HttpApplication object's constructor.
Now my question is, why shouldn't I put my startup logic in the constructor? Why does even Init() exist and do I need to care about Application_Start? If I do, can anyone explain why there is no proper event or overridable method for this pseudo-event in the HttpApplication object?
And can anyone explain to me why in a typical ASP.NET application, 8 instances of my HttpApplication are created (which causes the constructor and Init to run just as many times, of course; this can be mitigated with locking and a shared static boolean called initialized) when my application only has a single AppDomain?
explain reasons why the name property of a Repeater control's child controls would be generated differently in an ASP.NET application when it is deployed on different IIS servers?
One some IIS servers the Name is generated using the format:
String.Format("{0}:_ctl{1:00}:{2}", RepeaterControlID, itemIndex, ChildControlID);
e.g.
<input name="Mntc_Software_List:_ctl1:id" id="Mntc_Software_List__ctl1_id" type="hidden" value="1772" />
and on other IIS servers the format is:
String.Format("{0}$ctl{1}${2}", RepeaterControlID, itemIndex, ChildControlID);
e.g.
<input name="Mntc_Software_List$ctl01$id" type="hidden" id="Mntc_Software_List_ctl01_id" value="1772" />
In my repeater I am attempting to set the label format based on a value from my datasource. The following line from my repeater is straightforward enough but now how would I modify it if I wanted the "C2" statement in the ToString to pull from a field in my datasource named "MyFormat" which would contain either the C2 or N0 value? Basically switching the formatting for that label between currency and a double?
<asp:Label runat="server" ID="lblValue1" Text='<%# Convert.ToDouble(Eval("MyValue")).ToString("C2") %>'></asp:Label>
I've attempted to simply insert a statement such as Eval("MyFormat") in place of the "C2" statement but to no avail.
I need to assign string to repeater label on button click but it is showing error object reference not set
//Label date = (Label)Repeater.FindControl("ltpl_datefor");
Label date = Repeater.Items[0].FindControl("ltpl_datefor") as Label;
date.Text = dateforloop.ToString().Substring(0);
[Code].....
How do I text the string length of a field value in a repearter.
<asp:HyperLink ID="hypName12" runat="server" Visible='<%# (Convert.ToString(Eval("L_Name")) Length > 5 ) %>' ImageUrl="~/name12.gif" NavigateUrl='<%#
"http://" + Eval("L_Name") %>' Target="_blank" ></asp:HyperLink>
I want to show limited text in a linkbutton which is inside repeater control.. As repeater is configure with datasource...how can i do that...
View 1 RepliesThe repeater below allows a visitor to click a [+] to add a textbox. They can add as many as they need. Each textbox will contain a name.
[Code]....
I want to be able to collect all of the additional textboxes and add it to an string:
[Code]....
If for example the visitor added two textboxes and typed in "Mary" in the first and "Sue" in the second, I'd like "myAdditionalRegistrants" in the above string to be replaced with:
Mary <br /> Sue
I want to add a class to a div inside my repeater control based on whether the query string value is true or false, so that I can style it differently.
View 6 RepliesWhat is the difference between strings and string builder in asp.net?
View 3 RepliesI am using LINQ to SQL in my application. I have some fields like textbox and checkbox in my form. when i enter any text in textbox it should search the data in the database. it should display in some control. Here i want to write query in LINQ I want to use predicate builder. If we are using sql server we have to write in stored procedure but i dont want in stored procedure. plz tell how to use predicate builder and explaination.
View 1 Repliesreport builder row filtering?
View 3 Replies