This is a migrated thread and some comments may be shown as answers.

Bind ListView

1 Answer 78 Views
ListView
This is a migrated thread and some comments may be shown as answers.
MKM
Top achievements
Rank 1
MKM asked on 14 Aug 2012, 08:39 AM
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. 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Aug 2012, 09:16 AM
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.
Tags
ListView
Asked by
MKM
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or