Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void BtnID_Click(object sender, EventArgs e)
- {
- int id = Convert.ToInt32(TextBoxID.Text);
- try
- {
- List<ASPWebApp.CottagesServiceReference.Cottages> cottages = ws.GetCottageInfoByID(id).ToList();
- ListItem cottage = new ListItem(String.Join(".", cottages));
- BulletedList1.Items.Add(cottage);
- BulletedList1.DataSource = cottages;
- BulletedList1.DataBind();
- }
- catch (Exception a)
- {
- Console.WriteLine(a);
- }
- }
- public List<Cottages> GetCottageInfoByID(int id)
- {
- List<Cottages> cottage = new List<Cottages>();
- SqlConnection conn = new SqlConnection(dataSource);
- string sqlQuerySelectCottageInfo = "SELECT Cottage_Name as 'Name', Cottage_Location as Location, No_Of_Rooms as Rooms, Description, Cost_Per_Night as Cost FROM dbo.Cottages where Cottage_ID = @id";
- SqlCommand cmd = new SqlCommand(sqlQuerySelectCottageInfo);
- cmd.Parameters.AddWithValue("@id", id);
- conn.Open();
- cmd.Connection = conn;
- SqlDataReader reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- if (!reader.HasRows)
- {
- throw new Exception("No Cotteges Found");
- }
- else
- {
- cottage.Add(new Cottages()
- {
- Name = (reader[("Name")].ToString()),
- Location = (reader[("Location")].ToString()),
- Rooms = Convert.ToInt32(reader[("Rooms")]),
- Cost = Convert.ToDecimal(reader[("Cost")]),
- Description = (reader[("Description")].ToString()),
- });
- }
- }
- reader.Close();
- conn.Close();
- return cottage;
- }
- <td class="Column2" colspan="1">
- <asp:TextBox class="TxtID" ID="TextBoxID" runat="server" BorderColor="Gray" BorderStyle="Solid" BorderWidth="2px" CausesValidation="False"></asp:TextBox>
- <asp:Button class="BtnID" ID="BtnID" runat="server" Text="Search" OnClick="BtnID_Click" />
- <asp:BulletedList class="Bullets" ID="BulletedList1" runat="server">
- </asp:BulletedList>
- </td>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement