Bind ListView

2 posts, 0 answers
  1. MKM
    MKM avatar
    2 posts
    Member since:
    Aug 2012

    Posted 14 Aug 2012 Link to this post

    Hi all,


    My web page has got a asp:TextBox and a listview, initially the listview is not visisble.When user type a text inside the TextBox I want a listview bound with the database. Exactly my requirment is to bind list view depanding upon the value typed in the textbox.
    My sqlquery to extarct the value fron the db is."SELECT patientOrg, surgeryDate FROM DetailsChart WHERE patientName ="text from textbox"

    Reply as soon as possible.

    Thanks,
    Mkm. 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Aug 2012 Link to this post

    Hi MKM,

    Try the following code snippet to achieve your scenario.

    ASPX:
    <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostBack="true"></asp:TextBox>
    <telerik:RadListView ID="RadListView1" runat="server" ItemPlaceholderID="itemPlaceholder" Visible="false">
      <ItemTemplate>
         <tr align="left">
            <td align="center">
               <asp:Label ID="Label1" Text='<%# Bind("patientOrg") %>' runat="server" />
            </td>
            <td align="left">
               <asp:Label ID="Label2" Text='<%# Bind("surgeryDate") %>' runat="server" />
            </td>
         </tr>
      </ItemTemplate>
      <LayoutTemplate>
         <center>
            <table cellpadding="10" cellspacing="0" class="stripe" width="100%" id="tblResults">
               <tr>
                 <td width="50" align="center">
                    patientOrg
                 </td>
                 <td width="100" align="left">
                    surgeryDate
                 </td>
               </tr>
               <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
            </table>
         </center>
      </LayoutTemplate>
    </telerik:RadListView>

    C#:
    protected void TextBox1_TextChanged(object sender, EventArgs e)
     {
       TextBox txt = (TextBox)sender;
       string t = txt.Text;
       String s = "SELECT patientOrg,surgeryDate FROM DetailsChart WHERE patientName='" + t + "'";
       con.Open();
       SqlDataAdapter dr = new SqlDataAdapter(s, con);
       DataTable dt = new DataTable();
       dr.Fill(dt);
       con.Close();
       RadListView1.Visible = true;
       RadListView1.DataSource = dt;
       RadListView1.DataBind();
     }

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top