Ever needed to display more than one value in a bulleted list or dropdown, I did and here is how I ended up getting round it.
Using a normal bulleted list, we leave of the data source and on pageload run loadBulletedLists passing in the list and any variables to filter the stored stocedure used to populate it.
loadBulletedLists takes the recordset and inserts the results into the list, if there are two columns in a row is adds both seperated by a comma, if not it adds the one column.
aspx page
<asp:BulletedList ID="blBulletedList" runat="server" EnableViewState="True"></asp:BulletedList>
aspx.cs page
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
5: using System.Web.UI;
6: using System.Web.UI.WebControls;
7: using System.Data;
8: using System.Data.SqlClient;
9: using System.Configuration;
10: public partial class bridge_Default3 : System.Web.UI.Page
11: {
12: protected void Page_Load(object sender, EventArgs e)
13: {
14: if (!IsPostBack)
15: {
16: loadBulletedLists(blBulletedList,0);
17: }
18: }
19: protected void loadBulletedLists(object sender, object vParameter)
20: {
21: BulletedList blList = ((BulletedList)sender);
22: blList.Items.Clear();
23:
24: SqlConnection conn = null;
25: conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
26: SqlDataReader rdr = null;
27:
28: conn.Open();
29: SqlCommand cmd = new SqlCommand("selectBulletedListItems", conn);
30: cmd.CommandType = CommandType.StoredProcedure;
31: cmd.Parameters.Add(new SqlParameter("@Parameter", vParameter));
32:
33: string strColumn1;
34: string strColumn2;
35: rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
36: string strTitle = "";
37:
38: while (rdr.Read())
39: {
40: strColumn1 = rdr["fldColumn1"].ToString();
41: strColumn2 = rdr["fldColumn2"].ToString();
42: if (strColumn1 != "")
43: {
44: strTitle = strColumn1;
45: }
46: if (strColumn2 != "")
47: {
48: if (strTitle != "")
49: {
50: strTitle += ", " + strColumn2;
51: }
52: else
53: {
54: strTitle = strColumn2;
55: }
56: }
57: blList.Items.Add(new ListItem(strTitle));
58: }
59: }
60: }
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5