DataSource Controls :: Finding Code To Loop Through The Reader And Output The Details On Individual Lines Of The Page
Jan 14, 2010
I'm currently trying to build a html table from the results of a sql data reader. As my table has multiple records, I want the code to loop through the reader and output the details on individual lines of the page. In ASP I have done this in the past using something like
[Code]....
but as I am using data readers I'm not sure what the equivalent is.
I have some code in my vb.net code behind that queries a database, and if there is data, outputs it from the codebehind to a datalist on my asp.net page. In addition to sending the data to the datalist on the page, I need to take the value from "mbillaty" that is returned from the sql query, and have that value be the selected value for a drop down box also on the page. I can get either the datalist to fill, or the selected value for the dropdown box to be selected depending upon which bit of code I place before the other (ARGH), but I can't get them to both work together on the page. What am I doing wrong?
however I can only create the last image instead of 5 images.
- imageID - cat5
I assign each image unique ID.
If reader2.HasRows Then While reader2.Read Dim img1 = Convert.ToString(reader2("imgtag1")) Dim img2 = Convert.ToString(reader2("imgtag2")) Dim img3 = Convert.ToString(reader2("imgtag3")) Dim img4 = Convert.ToString(reader2("imgtag4")) Dim img5 = Convert.ToString(reader2("imgtag5")) Dim blogimg = Convert.ToString(reader2("ImageID")) Dim a As New HyperLink a.Attributes.Add("onclick", "return hs.expand(this)") a.Attributes.Add("href", "../../blog/images/" + blogimg) Dim img As Image = New Image img.ImageUrl = "~/blog/images/" + blogimg img.Width = 200 If img1 = "1" Then Dim blogimg1 As HtmlTableCell = CType(FindControl("blogimg1"), HtmlTableCell) img.ID = blogimg + "1" a.Controls.Add(img) blogimg1.Controls.Add(a) ListBox1.Items.Add(blogimg + "1") End If If img2 = "1" Then Dim blogimg2 As HtmlTableCell = CType(FindControl("blogimg2"), HtmlTableCell) img.ID = blogimg + "2" a.Controls.Add(img) blogimg2.Controls.Add(a) ListBox1.Items.Add(blogimg + "2") End If If img3 = "1" Then Dim blogimg3 As HtmlTableCell = CType(FindControl("blogimg3"), HtmlTableCell) img.ID = blogimg + "3" a.Controls.Add(img) blogimg3.Controls.Add(a) ListBox1.Items.Add(blogimg + "3") End If If img4 = "1" Then Dim blogimg4 As HtmlTableCell = CType(FindControl("blogimg4"), HtmlTableCell) img.ID = blogimg + "4" a.Controls.Add(img) blogimg4.Controls.Add(a) ListBox1.Items.Add(blogimg + "4") End If If img5 = "1" Then Dim blogimg5 As HtmlTableCell = CType(FindControl("blogimg5"), HtmlTableCell) img.ID = blogimg + "5" a.Controls.Add(img) blogimg5.Controls.Add(a) ListBox1.Items.Add(blogimg + "5") End If End While
My asp.net app used Crystal report to display as pdf file.
If I open the report in my pc (newest version, Adobe reader 9), it is ok but once I open app in web server (Adobe reader 8), it display a blank screen.
What I don't quite get is why the total database size is 642.56 MB when the size of the individual tables is so much smaller. We pay for the total amount, in chunks of 500 MB. I was trying to see which tables where causing the DB to be so big, but to me, it looks like it is not the size of the tables but something else.
What should I look at to figure out why we are taking up so much space? Am I not understanding how this works?
when need to insert into Text.boxes details from user (name,e-mail, e.tc.) and to get record of it into DB on other page. I try to get after pressing Submit btn:
I am getting error messages for the last two lines of the following button click event handler code where I am attempting to create a new record in my Profiles table with 3 column entries:
The first error message refers to the "Add" statement in the second to last line. It states, 'Syatem.Data.Linq.Table<Profile>' does not contain a definition for 'Add'. The last 2 errors refer to the last line. They state "The best overloaded method match for 'Syatem.Data.Linq.DataContext.SubmitChanges(Syatem.Data.Linq.ConflictMode)' has some invalid arguments" and "Argument '1': cannot convert from 'profile' to 'Syatem.Data.Linq. ConflictMode'".
I'm quite new to ASP.NET and i was wondering if someone could answer some of my questions.1. What is the difference between a DataTable and an Array? Is the DataTable a serverside control? Is it exposed to the user?2. Does the reader retrieve the column names? If so- how can I capture them? Are they the first row?2. Is it possible to populate an Array using the following sort of code, and if so- how?:
SqlCommand tableCommand = new SqlCommand(); SqlConnection tableConnection = new SqlConnection(); tableCommand.Connection = tableConnection;
I cant get my nested loop to output the right code:
If pagesreader.Read() Then ' if subtitle exists then output mydata = "<h2>" & pagesreader.Item("documentcategoryname") & "</h2>" While pagesreader.Read() mydata &= "<h2>" & pagesreader.Item("documentcategoryname") & "</h2>" If (pagesreader.Item("documentcat") = pagesreader.Item("documentcategoryid")) Then mydata &= "<p>" & pagesreader.Item("documentname") & "</p>" End If End While End If produces: About Us About Us doccy4 Map Of Medicine doccy5
When I need it to procude: About Us doccy3 doccy4 Map Of Medicine doccy
I need to know how to loop the user input value in textboxes programatically. For example I have 3 rows of textboxes i have programatically generated with id txtCategory1, txtCategory2, txtCategory3. Since I generated all these textboxes programatically I have no idea how many textboxes will be there. I need to do a looping again to get the value user put in into textbox. How can I get the value of textbox by using ID?
Here is the error I receive. How can I format the data that is coming from the data reader into currency format??? Also, is there a way to format it into currency without the dollar sign?
Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
I'm getting "This SqlTransaction has completed; it is no longer usable" exception when try to commit my transaction after sqlreader is close.Here is the code sample
[Code]....
...so when I get to commit the transaction it raises the mentioned exception: "This SqlTransaction has completed; it is no longer usable". I have also noticet that Command.Transaction becomes NULL after reader.Close()My question is: Can I use SqlDataReader and SqlTransaction ? Maybe to use BeginExecuteReader and EndExecuteReader ?
I have an SQL table which looks similar to the following:
Title | Author | Tags 'title1' 'author1' 'horror, steven king, clowns' 'title2' 'author2' 'childrens, roald dahl, chocolate'
Let's say I wanted to find the name of a book that has the tag 'clowns' in it...how can I do this? 'clowns' is a substring of the tag for 'title1'...but how do I search for substrings? I have tried to use the "LIKE" keyword but obviously it doesn't work in this situation.
I have been able to successfully read a row of data from an SQL table using two column parameters. Now I would like to update this row with new information. Is this possible since the reader does not specify which row was read with the 'reader.Read();' command?
After insert a grid or any other tool into an aspx page it generates enough code for that tool(for ex.): <dx:ASPxGridView ID=ASPxGridView1 runat="server"></dx:ASPxGridView>...
But,after adding any property to this control (like Show group Panel) it generates more than 3000 lines of code in aspx page () and after adding any other tool the code is increasing in a enormous way...
How can I reduce the code, maybe there is a property(settings) in DevExpress option...
I have a control in a content page that I want to find the width and left attributes of the style. I am trying to find this from Javascript code that exists on the Master Page. How do I do that?
I have a GV that is populated via a reader: Using reader As SqlDataReader = cmd.ExecuteReader() I have autogenerate edit button=T but it will not go into editmode. Must I create template to handle this?
I am trying to pass a mysql reader string variable into a textbox so on the asp front end it will automatically show the resultset as soon as the page is loaded. The following is my code:
protected void Page_Load(object sender, EventArgs e) { if (!Page.isPostback)
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]...
I have a Button1_Click event that I want to display the first 7 records of a dataset by looping through them and presenting on the page in a Literal Control. All of the database code is working fine because when I use the Response.Write statement below, the first 7 rows are dumped at the page top before the HTML. But, when I replace the Response.Write with the Literal1.Text as shown below, only the last (7th) record is displayed on the page.
Here is the code section in question:
for (int i = 0; i <= 6; i++) { DataRow dr = dt.Rows[i]; string text1 = dr["Question"].ToString(); //Response.Write(text1); Literal1.Text = text1; }