Hi all,

I am using DataList and when i run my project the table of the datalist doesn't appear?!!!

aspx.vb file

Imports System.Data.SqlClient

Public Class SLP_1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' TextBox1.Text = Session(logAccount)

    End Sub

    Protected Sub DataList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DataList1.SelectedIndexChanged
        Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\sony\Documents\Visual Studio 2010\Projects\SADA\SADA\App_Data\SADA2.mdf';Integrated Security=True;User Instance=True")

        Dim cmdStr As String = "SELECT PateintTbl.PateintId, PateintTbl.P_f_Name, PateintTbl.P_L_Name, PateintTbl.SLP_ID FROM PateintTbl INNER JOIN SLP ON PateintTbl.SLP_ID = Session(logAccount)"

        Dim da As SqlDataAdapter = New SqlDataAdapter(cmdStr, con)

        Dim ds As DataSet = New DataSet()
        da.Fill(ds, "imp")
        DataList1.DataSource() = ds
        DataList1.DataBind()

    End Sub
End Class

aspx file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:DataList ID="DataList1" runat="server" BackColor="#DEBA84" 
            BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
            CellSpacing="2" DataSourceID="SqlDataSource1" GridLines="Both">
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
        <asp:Label ID="Label1" runat="server" Text="test"></asp:Label>
        <br />
        <br />

    </div>
    </form>
</body>
</html>

Any idea?!!! plz help!!!!

Thanks in advance..

Not sure what you are trying to do here. In your datalist control, you have set the DataSourceID to "SqlDataSource1" which indicates that you ran through the wizard to associate this control to a datasoure. However, in the SqlDataSource control, you do not have it configured.

Then in your code behind, you are binding to this control, but on the SelectedIndexChanged event. Is this what you are intending to do?

It looks to me like your SQL statement is wrong. Where you use a join the ON clause is meant to specify which columns match but you haven't done that. You have 'ON PateintTbl.SLP_ID = Session(logAccount)'

This should be: ON PateintTble.SLP_ID = SLP.someMatchingColumn WHERE SLP_ID = ' + Session(logAccount) + ';''

Including Session(logAccount) directly in the string is also incorrect as that would be taken exactly as is, and not evaluated to the value Session(logAccount) holds.

Both JorgeM and hericles are correct in their points. The reason your DataList is not visible when you initialy start the app is because SqlDataSource1 has no query and thus DataList1 will contain no data and not display.

Thanks all for your replays

what i want to do is the therapist have more than one patient and what i want to do is displaying the names of the patient that assigned to this therapist and i want them to be displayed as links to redirect the therapist to the patient page

so am trying to do the first part which is the displaying the patient names .

I'll try to redo this form according to your advices

wish me luck :)

hi all,

I redo my form, but its still doesn't show the datalist

the aspx code

<form id="form1" runat="server">
    <div>

        <asp:Label ID="Label1" runat="server" Text="test"></asp:Label>
        <br />
        <asp:DataList ID="DataList1" runat="server" BackColor="#DEBA84" 
            BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
            CellSpacing="2" GridLines="Both">
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <ItemTemplate>
                <table class="style1">
                    <tr>
                        <td>
                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("PateintId") %>'></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="Label3" runat="server" Text='<%# Eval("P_f_Name") %>'></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="Label4" runat="server" Text='<%# Eval("P_L_Name") %>'></asp:Label>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
            <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
        </asp:DataList>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />

    </div>
    </form>

aspx.vb code

Imports System.Data.SqlClient

Public Class SLP_1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim Id As Int32 = Session("logAccount")

        TextBox1.Text = Id
    End Sub

    Protected Sub DataList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DataList1.SelectedIndexChanged

        Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\sony\Documents\Visual Studio 2010\Projects\SADA\SADA\App_Data\SADA2.mdf';Integrated Security=True;User Instance=True")

        Dim da As New Data.SqlClient.SqlDataAdapter("SELECT PateintTbl.PateintId, PateintTbl.P_f_Name, PateintTbl.P_L_Name, PateintTbl.SLP_ID FROM PateintTbl INNER JOIN SLP ON PateintTble.SLP_ID = SLP.SLP_ID WHERE SLP_ID = '" & TextBox1.Text & "'", con)


        Dim ds As DataSet = New DataSet()
        da.Fill(ds, "imp")
        DataList1.DataSource() = ds
        DataList1.DataBind()


    End Sub



End Class

any idea!!!
Do you think there is a better way insted of using Datalist?
Plz help :'(

The SelectedIndexChanged event is not really an appropriate place to call databinding - at least not your initial databind. This event only fires when an existing item in the DataList is Selected by the user. See here for more info.

You should try moving the code you have from this event into the Page_Load function and see what you get.

Hi all,
Thanks for your replays

I solved the problem :)

I discover that i can do what i want through the wizard by using WHERE

This is the final code

aspx page

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SLP_1.aspx.vb" Inherits="SADA.SLP_1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:Label ID="Label1" runat="server" Text="test"></asp:Label>
        <br />
        <asp:DataList ID="DataList1" runat="server" BackColor="#DEBA84" 
            BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
            CellSpacing="2" GridLines="Both" DataKeyField="PateintId" 
            DataSourceID="SqlDataSource1" RepeatDirection="Horizontal">
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <ItemTemplate>
                PateintId:
                <asp:Label ID="PateintIdLabel" runat="server" Text='<%# Eval("PateintId") %>' />
                <br />
                P_f_Name:
                <asp:Label ID="P_f_NameLabel" runat="server" Text='<%# Eval("P_f_Name") %>' />
                <br />
                P_L_Name:
                <asp:Label ID="P_L_NameLabel" runat="server" Text='<%# Eval("P_L_Name") %>' />
                <br />
                Slp_ID:
                <asp:Label ID="Slp_IDLabel" runat="server" Text='<%# Eval("Slp_ID") %>' />
                <br />
                <br />
            </ItemTemplate>
            <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <SelectedItemTemplate>
                <table class="style1">
                    <tr>
                        <td>
                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("PateintId") %>'></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="Label3" runat="server" Text='<%# Eval("P_f_Name") %>'></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="Label4" runat="server" Text='<%# Eval("P_L_Name") %>'></asp:Label>
                        </td>
                    </tr>
                </table>
            </SelectedItemTemplate>
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT [PateintId], [P_f_Name], [P_L_Name], [Slp_ID] FROM [PateintTbl] WHERE ([Slp_ID] = @Slp_ID)">
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBox1" Name="Slp_ID" PropertyName="Text" 
                    Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:TextBox ID="TextBox1" runat="server" Visible="False"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" PostBackUrl="~/SLPMain.aspx" 
            Text="Next" />
        <br />
        <br />

    </div>
    </form>
</body>
</html>

aspx.vb page

Public Class SLP_1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim Id As Int32 = Session("logAccount")

        TextBox1.Text = Id


    End Sub
End class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.