Last post Jun 02, 2009 03:55 AM by wildshot
May 22, 2009 03:15 AM|wildshot|LINK
I have written a web page which connects to a database and then display 3 values from a management reporting system using the database.
I am accessing a database using the following code:
<asp:SqlDataSource ID="SqlToVersion" runat="server"
ConnectionString="<%$ ConnectionStrings:WebImportOnServer %>"
SelectCommand="SELECT [VerNo], [PeriodName], [PeriodNo] FROM [atblVersion]"
<asp:DetailsView ID="DetView" runat="server" DataSourceID="SqlToVersion"
<asp:BoundField DataField="VerNo" HeaderText="Spreadsheet Version Number" ReadOnly="True" />
<asp:BoundField DataField="PeriodName" HeaderText="Reporting Period" ReadOnly="True"
<asp:BoundField DataField="PeriodNo" HeaderText="Period Number" ReadOnly="True"
This works perfectly, but I need to take the values displayed in the 3 datafields (VerNo , PeriodName PeriodNo ) and use them as variables in a file that is being generated from the web page. The file is generated by using a stored procedure and these 3 variables
are used in this, with entries manually entered into text boxes.
My variables are defined in this manner:
Dim vcPeriodNo As Integer = ????
but it is how to replace the question marks with valid code that takes the values from the bound fields that I am stuck with. Can anyone offer any advice, I know it should be simple but I have hit a complete block.
May 22, 2009 05:39 AM|TheRed|LINK
You could write:
Dim myTXT as TextBox = CType(DetView.FindControl("VerNo"),TextBox)
Dim vcPeriodNo As Integer = Cint(myTXT.Text)
May 22, 2009 05:43 AM|sumitd|LINK
Dim vcVerNo As Integer
Dim vcPeriodName As String
Dim vcPeriodNo As Integer
For Each row As GridViewRow In GridView1.Rows
vcVerNo= DirectCast(row.Cells.Text, Integer)
Jun 02, 2009 03:55 AM|wildshot|LINK
Thanks for the suggestions, have now resolved the problem. Had a slight problem at first as I was using the square brackets  as displayed in the answer. I could not see what was wrong - changed them to round brackets () and all was fine.