If you want to access the values of the controls you display on the
page, then you again have to loop through the datareader or dataset you
have been using to create the controls on the page.
 
In the loop you can make use of the IDs of the controls to see if they
are on the page, if yes, find its type, then get its value.  Here is an
example:
 
Lets say you have a list of IDs of the controls in a column (say
strControlName) of a table in the database.
While looping through this dataset or datareader, you can do the
following:
 
If (this.FindControl(strControlName) != null)
{
            if(this.FindControl(strControlName).GetType() ==
typeof(TextBox))
                        {
                                    string strValue = ((TextBox)
(this.FindControl(strControlName)).Text;
}
}
 
Hope this helps.
 
Rajendra.
 
-----Original Message-----
From: moron_psychomaniac [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 15, 2004 12:11 AM
To: [EMAIL PROTECTED]
Subject: [AspNetAnyQuestionIsOk] Dynamic ASP.NET WebForm
 
I'm trying to build a dynamic web form using ASP.NET.
Basically I've defined all the fields for the form in the database.
When the aspx is launched, it will first grab those values from the 
SQL DB as an XML, then I'm using XSLT to display the form.
Here's the background VB code:

    Public Sub displayForm()
        Dim sqlconn As New Data.SqlClient.SqlConnection
        Dim sqlcmd As New Data.SqlClient.SqlCommand
        Dim myXR As System.Xml.XmlTextReader
        Dim xmldoc As New XmlDocument
        Dim strXMLHeaderTag As String

        Try
            sqlconn.ConnectionString = Application("SQLConnStr")
            sqlconn.Open()

            sqlcmd.Connection = sqlconn
            sqlcmd.CommandText = "SELECT * FROM tblFormField Field 
ORDER BY Field.FieldOrder FOR XML AUTO, ELEMENTS"

            myXR = sqlcmd.ExecuteXmlReader()
            myXR.MoveToContent()

            'Because XMLDOC will only accept well-formatted XML 
string: XML wrapped within 1 top-root-tag
            strXMLHeaderTag = "<Top>"
            While Not myXR.EOF
                strXMLHeaderTag &= myXR.ReadOuterXml
            End While
            strXMLHeaderTag &= "</Top>"

            xmldoc.LoadXml(strXMLHeaderTag)
            Dim xslTran As XslTransform = New XslTransform
            xslTran.Load(Server.MapPath("test.xslt"))

            Dim sw As StringWriter
            sw = New StringWriter
            xslTran.Transform(xmldoc, Nothing, sw)

            Response.Write(sw.ToString)

        Catch exp As Exception
            Response.Write("Error in opening DB! index.displayform() " 
& exp.ToString)
        End Try
    End Sub

And this is the XSLT:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:template match="/">
  <table border="0">
    <xsl:for-each select="Top/Field">
      <tr>
      <xsl:variable name="fieldname" select="FieldName" /> 
        <xsl:variable name="fieldorder" select="FieldOrder" />
        <td><xsl:value-of select="NameDisplay"/>: </td>
        <td><INPUT id="txt{$fieldorder}" style="WIDTH: 190px; HEIGHT: 
22px" size="29" name="{$fieldname}"/></td>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>
</xsl:stylesheet>

Everything is okay until this point. It can display the form 
correctly.
However, I'm confused as how to grabs the user-input values from the 
textbox?
Because when user click the "Submit" button, back to the VB code, in 
the Submit_Click() function, I'm supposed to get the value of each 
textbox. But then, I can't simply just do "textboxname.Text", because 
the name of the textbox itself is only defined during run-time (in the 
XSLT)!

And how can I make an iteration to make sure that I get all the 
textboxes (Note that the number of textboxes in the form varies 
depending on how many fields I've defined in the DB).

Can anybody help? Thanks a lot!

Adrian





Yahoo! Groups Sponsor
ADVERTISEMENT
click here
<http://us.ard.yahoo.com/SIG=129ngb17s/M=295196.4901138.6071305.3001176/
D=groups/S=1705006764:HM/EXP=1095308881/A=2128215/R=0/SIG=10se96mf6/*htt
p:/companion.yahoo.com> 
 
<http://us.adserver.yahoo.com/l?M=295196.4901138.6071305.3001176/D=group
s/S=:HM/A=2128215/rand=221871624> 
 
  _____  

Yahoo! Groups Links
*         To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
  
*         To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]
cribe> 
  
*         Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> . 


[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to