Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Help!! Repeater OnItemCommand Problem :(
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Help!! Repeater OnItemCommand Problem :(

 Post Reply Post Reply
Author
MrCarl View Drop Down
Newbie
Newbie


Joined: 29 March 2003
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote MrCarl Quote  Post ReplyReply Direct Link To This Post Topic: Help!! Repeater OnItemCommand Problem :(
    Posted: 05 February 2004 at 8:09am
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
Back to Top
MrCarl View Drop Down
Newbie
Newbie


Joined: 29 March 2003
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote MrCarl Quote  Post ReplyReply Direct Link To This Post Posted: 05 February 2004 at 10:17am

Cured with a very simple:

If Not IsPostback Then

    subBindCv() 
   
End If

- Carl S

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.