R
rn5a
Consider the following code:
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(".........")
sqlDapter = New SqlDataAdapter("SELECT * FROM NETUsers",
sqlConn)
dSet = New DataSet()
sqlDapter.Fill(dSet, "Users")
rptrUsers.DataSource = dSet
rptrUsers.DataMember = "Users"
rptrUsers.DataBind()
sqlConn.Close()
End If
End Sub
Sub ItemList(ByVal obj As Object, ByVal ea As
RepeaterCommandEventArgs)
lblCmdSource.Text = "CommandName: " & ea.CommandName
lblCmdSource.Text += "<br>CommandSource: " &
CType(ea.CommandSource, LinkButton).Text"
lblCmdSource.Text += "<br>CommandArgument: " &
ea.CommandArgument
End Sub
Sub BindData(ByVal obj As Object, ByVal ea As
RepeaterItemEventArgs)
Response.Write("Item Data Bound<br>")
'rptrUsers.DataBind()
End Sub
Sub ItemCreated(ByVal obj As Object, ByVal ea As
RepeaterItemEventArgs)
Response.Write("Item Created<br>")
'rptrUsers.DataBind()
End Sub
</script>
<form runat="server">
<asp:Repeater ID="rptrUsers" OnItemCommand="ItemList"
OnItemCreated="ItemCreated" OnItemDataBound="BindData" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th>NAME</th>
<th>PHONE NO.</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<th>
<asp:LinkButton ID="lnkName" CommandArgument='<%#
Container.DataItem("LastName") %>' CommandName='<%#
Container.DataItem("FirstName") %>' Text='<%#
Container.DataItem("FirstName") & " " & Container.DataItem("LastName")
%>' runat="server"></asp:LinkButton>
</th>
<th><%# Container.DataItem("Phone") %></th>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Label ID="lblCmdSource" runat="server"/>
</form>
As such the above code works fine. Please note the 2 commented lines
(rptrUsers.DataBind()) in the subs BindData & ItemCreated. If I
uncomment either or both of these lines, then the above code doesn't
get executed. Instead it just displays a message saying "Server
Application Unavailable".
Now why is the presence of the line - rptrUsers.DataBind() - in the 2
subs BindItem & ItemCreated not allowing the ASPX code to get
executed?
Thanks....
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(".........")
sqlDapter = New SqlDataAdapter("SELECT * FROM NETUsers",
sqlConn)
dSet = New DataSet()
sqlDapter.Fill(dSet, "Users")
rptrUsers.DataSource = dSet
rptrUsers.DataMember = "Users"
rptrUsers.DataBind()
sqlConn.Close()
End If
End Sub
Sub ItemList(ByVal obj As Object, ByVal ea As
RepeaterCommandEventArgs)
lblCmdSource.Text = "CommandName: " & ea.CommandName
lblCmdSource.Text += "<br>CommandSource: " &
CType(ea.CommandSource, LinkButton).Text"
lblCmdSource.Text += "<br>CommandArgument: " &
ea.CommandArgument
End Sub
Sub BindData(ByVal obj As Object, ByVal ea As
RepeaterItemEventArgs)
Response.Write("Item Data Bound<br>")
'rptrUsers.DataBind()
End Sub
Sub ItemCreated(ByVal obj As Object, ByVal ea As
RepeaterItemEventArgs)
Response.Write("Item Created<br>")
'rptrUsers.DataBind()
End Sub
</script>
<form runat="server">
<asp:Repeater ID="rptrUsers" OnItemCommand="ItemList"
OnItemCreated="ItemCreated" OnItemDataBound="BindData" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th>NAME</th>
<th>PHONE NO.</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<th>
<asp:LinkButton ID="lnkName" CommandArgument='<%#
Container.DataItem("LastName") %>' CommandName='<%#
Container.DataItem("FirstName") %>' Text='<%#
Container.DataItem("FirstName") & " " & Container.DataItem("LastName")
%>' runat="server"></asp:LinkButton>
</th>
<th><%# Container.DataItem("Phone") %></th>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Label ID="lblCmdSource" runat="server"/>
</form>
As such the above code works fine. Please note the 2 commented lines
(rptrUsers.DataBind()) in the subs BindData & ItemCreated. If I
uncomment either or both of these lines, then the above code doesn't
get executed. Instead it just displays a message saying "Server
Application Unavailable".
Now why is the presence of the line - rptrUsers.DataBind() - in the 2
subs BindItem & ItemCreated not allowing the ASPX code to get
executed?
Thanks....