Hi,
I have a repeater which uses the OnItemCommand to execute a sub procedure which processes a form which is in the repeater... But it just doesnt seem to work... No errors get thrown up, and if I submit the form the page just reloads and nothing has been inserted into the database...
Please help!! Im tearing my hair out now!! hehe
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
subBindCv()
End Sub
Dim dsCv as New DataSet()
Sub subBindCv
Dim conSql as New SqlConnection(ConfigurationSettings.AppSettings("strCon"))
Dim strSqlCv as String = "SELECT tblCvAttachments.idCvAttachment, tblCvAttachments.strName, tblCvAttachments.txtComments, tblFileUpload.idFileUpload, tblFileUpload.strFileName, tblFileUpload.intSize " _
& "FROM tblCvAttachments " _
& "INNER JOIN tblFileUpload ON tblCvAttachments.fk_idFileUpload = tblFileUpload.idFileUpload ;"
Dim strSqlCvNotes as String = "SELECT tblNotes.fk_id, tblNotes.fk_table, tblNotes.txtNote " _
& "FROM tblNotes;"
Dim mySqlCvCommand as New SqlCommand(strSqlCv, conSql)
Dim mySqlCvDataAdapter as New SqlDataAdapter(mySqlCvCommand)
Dim mySqlCvNotesCommand as New SqlCommand(strSqlCvNotes, conSql)
Dim mySqlCvNotesDataAdapter as New SqlDataAdapter(mySqlCvNotesCommand)
conSql.Open()
mySqlCvDataAdapter.Fill(dsCv, "tblCvAttachments")
mySqlCvNotesDataAdapter.Fill(dsCv, "tblNotes")
conSql.Close()
repCvs.DataSource = dsCv.Tables("tblCvAttachments")
repCvs.DataBind()
End Sub
Sub subBindCvNotes(sender as Object, e as RepeaterItemEventArgs)
Dim intCvId = CType(e.Item.FindControl("frmIdCvAttachment"), HtmlInputHidden).Value
Dim myCvNotesDataView as DataView = dsCv.Tables("tblNotes").DefaultView
myCvNotesDataView.RowFilter = "fk_id = " & intCvId & " AND fk_table = 'tblCvAttachments'"
CType(e.Item.FindControl("repCvNotes"), Repeater).DataSource = myCvNotesDataView
CType(e.Item.FindControl("repCvNotes"), Repeater).DataBind
End Sub
Sub subAddCvNote(sender as Object, e as RepeaterCommandEventArgs)
Dim conSql as New SqlConnection(ConfigurationSettings.AppSettings("strCon"))
Dim strSql As String = "INSERT INTO tblNotes (tblNotes.fk_id, tblNotes.fk_table, tblNotes.txtNote) " _
& "VALUES (@fk_id, @fk_table, @txtNote);"
Dim cmdSql = New SqlCommand(strSQL, conSql)
Dim storFk_id as New SqlParameter("@fk_id", SqlDbType.Int, 4)
storFk_id.Value = CInt(CType(e.Item.FindControl("frmIdCvAttachment"), HtmlInputHidden).Value)
cmdSql.Parameters.Add(storFk_id)
Dim storFk_table as New SqlParameter("@fk_table", SqlDbType.VarChar, 255)
storFk_table.Value = "tblCvAttachments"
cmdSql.Parameters.Add(storFk_table)
Dim storTxtNote as New SqlParameter("@txtNote", SqlDbType.Text, 16)
storTxtNote.Value = Trim(CType(e.Item.FindControl("frmNote"), TextBox).Text)
cmdSql.Parameters.Add(storTxtNote)
conSql.Open()
cmdSql.ExecuteNonQuery()
conSql.Close()
subBindCv()
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Repeater</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form runat="server">
<asp:Repeater id="repCvs" runat="server" OnItemCommand="subAddCvNote" OnItemDataBound="subBindCvNotes">
<ItemTemplate>
<table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#000000" class="itemTableStyle">
<tr class="itemTableHeader">
<td colspan="2">CV added as file attachment by ??? of Westmead on ???.</td>
</tr>
<tr>
<td width="95">Name on CV :</td>
<td width="400"><%#Container.DataItem("strName")%></ td>
</tr>
</table>
<br>
<input name="hidden" type="hidden" id="frmIdCvAttachment" value='<%#Container.DataItem("idCvAttachment")%>' runat="server">
<table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#000000" class="itemTableStyle">
<tr>
<td colspan="2" class="itemTableHeader"><%#Container.DataItem("strName ")%> CV Notes : </td>
</tr>
<asp:Repeater id="repCvNotes" runat="server">
<ItemTemplate>
<tr>
<td colspan="2"><%#Container.DataItem("txtNote")%></ td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr>
<td colspan="2">If you wish to add a note to this vacancy please use the form below :<br>
<asp:TextBox id="frmNote" runat="server" CssClass="form" TextMode="MultiLine" Rows="5" Columns="60"></asp:TextBox>
<asp:Button id="subAddCvNote" runat="server" CssClass="formButton" Text="Submit"></asp:Button>
</td>
</tr>
</table>
<br>
<hr size="1">
<br>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
- Carl S