944,131 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1113
  • ASP.NET RSS
May 2nd, 2007
0

Classic to .net migration question

Expand Post »
Good afternoon all,
I'm currently migrating a classic app to .net and need to know the best practice in binding the data I pull through my querystring to the controls in my edit form.

In the classic app I assign the control(txtauthor) a value(<%=docauthor%>) from a variable(docauthor), via the id passed through the querysting:

ASP.NET Syntax (Toggle Plain Text)
  1. <%
  2. Response.Buffer=true
  3. 'VARIABLES
  4. dim objcon, objrs1, num, bgcolo, getcon, catname, id, descr,BacktoText,BacktoLink, docdatecreated
  5. dim id1, txtdocident, txtauthor, txtdoctype, txtlocation, txtdeptnumber, docident, doctype, doctitle, docvol, dockeyword, docsumm, docrel, docdatereq
  6. dim docassby, docdateappr, docrecby, docloc, docresp, docauthor, docref, docdept, dochardcopy, docpdfhyper, docdochyper, bAuto
  7. 'DOCUMENT CODE
  8. dim intDocID : intDocID = Request.QueryString("intDocID")
  9. dim strDocID : strDocID = Request.QueryString("strDocID")
  10. blnCont = false
  11. if len(intDocID) > 0 and isnumeric(intDocID) then
  12. strSQL = "select * from tblDocument where id = '" & intDocID & "'"
  13. blnCont = true
  14. else
  15. if len(strDocID) > 0 then
  16. strSQL = "select * from tblDocument where docident = '" & strDocID & "'"
  17. blnCont = true
  18. end if
  19. end if
  20. if blnCont = true then
  21. call ConnectDB()
  22. Set objRS = Server.CreateObject("ADODB.Recordset")
  23. objRS.Open strSQL,objCONN
  24. if CheckRS(objRS) then
  25. ID = objRS("ID")
  26. intDocID = objRS("ID")
  27. bAuto = objRS("bAuto")
  28. docident = objRS("docident")
  29. docvol = objRS("docvol")
  30. doctype = objRS("doctype")
  31. doctitle = objRS("doctitle")
  32. dockeyword = objRS("dockeyword")
  33. docsumm = objRS("docsumm")
  34. docrel = objRS("docrel")
  35. docdatereq = objRS("docdatereq")
  36. docassby = objRS("docassby")
  37. docdateappr = objRS("docdateappr")
  38. docrecby = objRS("docrecby")
  39. docloc = objRS("docloc")
  40. docresp = objRS("docresp")
  41. docauthor = objRS("docauthor")
  42. docref = objRS("docref")
  43. dochardcopy = objRS("dochardcopy")
  44. docdept = objRS("docdept")
  45. docdatecreated = objRS("docdatecreated")
  46. end if
  47. call DisConnectDB()
  48. end if


ASP.NET Syntax (Toggle Plain Text)
  1. <BODY LANGUAGE=javascript onload="return window_onload()" leftmargin="0" topmargin="0">
  2. <FORM NAME="frmdocumententry" ID="frmdocumententry" method="post">
  3. <input type=hidden name=id id=id value="<%=id%>">
  4. <input type=hidden name=bAuto id=bAuto value="<%=bAuto%>">
  5. <input type=hidden name=docidenthidden id=docidenthidden value="">
  6. <input type=hidden name=intDocID id=intDocID value="<%=ID%>">
  7. <input type=hidden name=strDocID id=strDocID value="<%=strDocID%>">
  8. <BR>
  9. <table align="center" table-layout:fixed width="800" border="0"
  10. <tr bgcolor="#F4F9FE">
  11. <td align="center" width = "25%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Author:</font></td>
  12. <td align="center" width = "25%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Dept. Number:</font></td>
  13. </tr>
  14. <tr>
  15. <td align="center" width = "25%"><INPUT TYPE=text NAME=txtauthor="text" SIZE="15" MAXLENGTH="30" value="<%=docauthor%>"></td></td>
  16. <td align="center" width = "25%">
  17. <select size=1 name="DEPT" id="DEPT" onchange=document.frmdocumententry.txtdeptnumber.value=this.value>
  18. <option value=""><%
  19. set objRS = GetDepts()
  20. do while not objRS.eof%>
  21. <option value="<%=objRS.fields("strdepnum")%>"<%if docdept = cstr(objRS.fields("strdepnum")) then%>SELECTED<%end if%>><%=objRS("strDepname")%>
  22. <%objRS.movenext
  23. loop
  24. set objRS = nothing%>
  25. </select>
  26. <INPUT TYPE=hidden NAME=txtdeptnumber class="text" SIZE="20" MAXLENGTH="25" value="<%=docdept%>">
  27. </td>




The following is the .Net code:

ASP.NET Syntax (Toggle Plain Text)
  1. <%
  2.  
  3. Response.Buffer=true
  4. 'VARIABLES()
  5.  
  6. 'DOCUMENT CODE
  7. Dim intDocID : intDocID = Request.QueryString("intDocID")
  8. Dim strDocID : strDocID = Request.QueryString("strDocID")
  9.  
  10. blnCont = False
  11.  
  12. If Len(intDocID) > 0 And IsNumeric(intDocID) Then
  13. strSQL = "select * from tblDocument where id = '" & intDocID & "'"
  14. blnCont = True
  15. Else
  16. If Len(strDocID) > 0 Then
  17. strSQL = "select * from tblDocument where docident = '" & strDocID & "'"
  18. blnCont = True
  19. End If
  20.  
  21. End If
  22.  
  23. If blnCont = True Then
  24.  
  25. Dim strCONN As New Data.SqlClient.SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TechLibrary;Data Source=TXXPW320\SQLSHOGUN")
  26.  
  27. 'setup command object
  28. Dim Command As New Data.SqlClient.SqlCommand(strSQL, strCONN)
  29. 'open connection
  30. strCONN.Open()
  31. 'do whatever with the reader
  32. reader = Command.ExecuteReader()
  33. Do While reader.Read
  34. ID = reader("ID")
  35. docident = reader("docident")
  36. bAuto = reader("bAuto")
  37. 'intDocID = reader("ID")
  38. docvol = fixNullEntries(reader("docvol"))
  39. doctype = fixNullEntries(reader("doctype"))
  40. doctitle = fixNullEntries(reader("doctitle"))
  41. dockeyword = fixNullEntries(reader("dockeyword"))
  42. docsumm = fixNullEntries(reader("docsumm"))
  43. docrel = fixNullEntries(reader("docrel"))
  44. docdatereq = fixDates(reader("docdatereq"))
  45. docassby = fixNullEntries(reader("docassby"))
  46. docdateappr = fixDates(reader("docdateappr"))
  47. docrecby = fixNullEntries(reader("docrecby"))
  48. docloc = fixNullEntries(reader("docloc"))
  49. docresp = fixNullEntries(reader("docresp"))
  50. docauthor = fixNullEntries(reader("docauthor"))
  51. docref = fixNullEntries(reader("docref"))
  52. docdept = fixNullEntries(reader("docdept"))
  53. docchangedate = fixDates(reader("docchangedate"))
  54. dochardcopy = fixNullEntries(reader("dochardcopy"))
  55.  
  56. Me.txtauthor.Text = docauthor????
  57.  
  58. Loop
  59. Call mf.DisConnectDB()
  60. End If
  61.  
  62.  
  63. %>
ASP.NET Syntax (Toggle Plain Text)
  1. <body>
  2. <form id="frmdocumententry" runat="server">
  3. <input type=hidden name=id id=id value="<%=id%>">
  4. <input type=hidden name=bAuto id=bAuto value="<%=bAuto%>">
  5. <input type=hidden name=docidenthidden id=docidenthidden value="">
  6. <input type=hidden name=intDocID id=intDocID value="<%=ID%>">
  7. <input type=hidden name=strDocID id=strDocID value="<%=strDocID%>">
  8. <div>
  9. <table border="0" align="center" cellpadding="5" cellspacing="5" style="table-layout: fixed; width: 850px;">
  10. <tr bgcolor="#F4F9FE">
  11. <td align="center" width = "25%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Author:</font></td>
  12. <td align="center" width = "25%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Dept. Number:</font></td>
  13. </tr>
  14.  
  15. <tr>
  16.  
  17. <td align="center" width = "25%" style="height: 5px"><asp:TextBox ID="txtauthor" runat="server" CssClass="text"></asp:TextBox>
  18. </td>
  19. <td align="center" width = "25%" style="height: 5px">
  20. <asp:DropDownList ID="cmbDept" runat="server" DataSourceID="deptDS" AutoPostBack=true DataTextField="strDepname" DataValueField="strDepname">
  21. </asp:DropDownList>
  22. <asp:SqlDataSource ID="deptDS" runat="server" ConnectionString="<%$ ConnectionStrings:techlibraryConnectionString %>"
  23. SelectCommand="SELECT [strDepname] FROM [tblDept]">
  24. </asp:SqlDataSource>
  25. &nbsp; &nbsp;&nbsp;
  26.  
  27. </td>

In the .Net app, I'd like to do the same as the classic app but there is no "Value" piece to the "asp:textbox" control. Is there a better way to assign the value to the control without hardcoding the relationship like in the following:
Me.txtauthor.text = docauthor????

Also, for the dept list, which is a lookup table, the querystring passes in a numeric value associated to the value from it's table. If i do an edit how would I pass that numeric value back in to display the current selection in the dropdown?


Thanks in advance,
CG
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cgdotnet is offline Offline
1 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Please help me...
Next Thread in ASP.NET Forum Timeline: need u r help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC