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:
<%
Response.Buffer=true
'VARIABLES
dim objcon, objrs1, num, bgcolo, getcon, catname, id, descr,BacktoText,BacktoLink, docdatecreated
dim id1, txtdocident, txtauthor, txtdoctype, txtlocation, txtdeptnumber, docident, doctype, doctitle, docvol, dockeyword, docsumm, docrel, docdatereq
dim docassby, docdateappr, docrecby, docloc, docresp, docauthor, docref, docdept, dochardcopy, docpdfhyper, docdochyper, bAuto
'DOCUMENT CODE
dim intDocID : intDocID = Request.QueryString("intDocID")
dim strDocID : strDocID = Request.QueryString("strDocID")
blnCont = false
if len(intDocID) > 0 and isnumeric(intDocID) then
strSQL = "select * from tblDocument where id = '" & intDocID & "'"
blnCont = true
else
if len(strDocID) > 0 then
strSQL = "select * from tblDocument where docident = '" & strDocID & "'"
blnCont = true
end if
end if
if blnCont = true then
call ConnectDB()
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL,objCONN
if CheckRS(objRS) then
ID = objRS("ID")
intDocID = objRS("ID")
bAuto = objRS("bAuto")
docident = objRS("docident")
docvol = objRS("docvol")
doctype = objRS("doctype")
doctitle = objRS("doctitle")
dockeyword = objRS("dockeyword")
docsumm = objRS("docsumm")
docrel = objRS("docrel")
docdatereq = objRS("docdatereq")
docassby = objRS("docassby")
docdateappr = objRS("docdateappr")
docrecby = objRS("docrecby")
docloc = objRS("docloc")
docresp = objRS("docresp")
docauthor = objRS("docauthor")
docref = objRS("docref")
dochardcopy = objRS("dochardcopy")
docdept = objRS("docdept")
docdatecreated = objRS("docdatecreated")
end if
call DisConnectDB()
end if
<BODY LANGUAGE=javascript onload="return window_onload()" leftmargin="0" topmargin="0">
<FORM NAME="frmdocumententry" ID="frmdocumententry" method="post">
<input type=hidden name=id id=id value="<%=id%>">
<input type=hidden name=bAuto id=bAuto value="<%=bAuto%>">
<input type=hidden name=docidenthidden id=docidenthidden value="">
<input type=hidden name=intDocID id=intDocID value="<%=ID%>">
<input type=hidden name=strDocID id=strDocID value="<%=strDocID%>">
<BR>
<table align="center" table-layout:fixed width="800" border="0"
<tr bgcolor="#F4F9FE">
<td align="center" width = "25%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Author:</font></td>
<td align="center" width = "25%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Dept. Number:</font></td>
</tr>
<tr>
<td align="center" width = "25%"><INPUT TYPE=text NAME=txtauthor="text" SIZE="15" MAXLENGTH="30" value="<%=docauthor%>"></td></td>
<td align="center" width = "25%">
<select size=1 name="DEPT" id="DEPT" onchange=document.frmdocumententry.txtdeptnumber.value=this.value>
<option value=""><%
set objRS = GetDepts()
do while not objRS.eof%>
<option value="<%=objRS.fields("strdepnum")%>"<%if docdept = cstr(objRS.fields("strdepnum")) then%>SELECTED<%end if%>><%=objRS("strDepname")%>
<%objRS.movenext
loop
set objRS = nothing%>
</select>
<INPUT TYPE=hidden NAME=txtdeptnumber class="text" SIZE="20" MAXLENGTH="25" value="<%=docdept%>">
</td>
The following is the .Net code:
<%
Response.Buffer=true
'VARIABLES()
'DOCUMENT CODE
Dim intDocID : intDocID = Request.QueryString("intDocID")
Dim strDocID : strDocID = Request.QueryString("strDocID")
blnCont = False
If Len(intDocID) > 0 And IsNumeric(intDocID) Then
strSQL = "select * from tblDocument where id = '" & intDocID & "'"
blnCont = True
Else
If Len(strDocID) > 0 Then
strSQL = "select * from tblDocument where docident = '" & strDocID & "'"
blnCont = True
End If
End If
If blnCont = True Then
Dim strCONN As New Data.SqlClient.SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TechLibrary;Data Source=TXXPW320\SQLSHOGUN")
'setup command object
Dim Command As New Data.SqlClient.SqlCommand(strSQL, strCONN)
'open connection
strCONN.Open()
'do whatever with the reader
reader = Command.ExecuteReader()
Do While reader.Read
ID = reader("ID")
docident = reader("docident")
bAuto = reader("bAuto")
'intDocID = reader("ID")
docvol = fixNullEntries(reader("docvol"))
doctype = fixNullEntries(reader("doctype"))
doctitle = fixNullEntries(reader("doctitle"))
dockeyword = fixNullEntries(reader("dockeyword"))
docsumm = fixNullEntries(reader("docsumm"))
docrel = fixNullEntries(reader("docrel"))
docdatereq = fixDates(reader("docdatereq"))
docassby = fixNullEntries(reader("docassby"))
docdateappr = fixDates(reader("docdateappr"))
docrecby = fixNullEntries(reader("docrecby"))
docloc = fixNullEntries(reader("docloc"))
docresp = fixNullEntries(reader("docresp"))
docauthor = fixNullEntries(reader("docauthor"))
docref = fixNullEntries(reader("docref"))
docdept = fixNullEntries(reader("docdept"))
docchangedate = fixDates(reader("docchangedate"))
dochardcopy = fixNullEntries(reader("dochardcopy"))
Me.txtauthor.Text = docauthor????
Loop
Call mf.DisConnectDB()
End If
%>
<body>
<form id="frmdocumententry" runat="server">
<input type=hidden name=id id=id value="<%=id%>">
<input type=hidden name=bAuto id=bAuto value="<%=bAuto%>">
<input type=hidden name=docidenthidden id=docidenthidden value="">
<input type=hidden name=intDocID id=intDocID value="<%=ID%>">
<input type=hidden name=strDocID id=strDocID value="<%=strDocID%>">
<div>
<table border="0" align="center" cellpadding="5" cellspacing="5" style="table-layout: fixed; width: 850px;">
<tr bgcolor="#F4F9FE">
<td align="center" width = "25%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Author:</font></td>
<td align="center" width = "25%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Dept. Number:</font></td>
</tr>
<tr>
<td align="center" width = "25%" style="height: 5px"><asp:TextBox ID="txtauthor" runat="server" CssClass="text"></asp:TextBox>
</td>
<td align="center" width = "25%" style="height: 5px">
<asp:DropDownList ID="cmbDept" runat="server" DataSourceID="deptDS" AutoPostBack=true DataTextField="strDepname" DataValueField="strDepname">
</asp:DropDownList>
<asp:SqlDataSource ID="deptDS" runat="server" ConnectionString="<%$ ConnectionStrings:techlibraryConnectionString %>"
SelectCommand="SELECT [strDepname] FROM [tblDept]">
</asp:SqlDataSource>
</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