Click here to Skip to main content
15,896,541 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using the below mentioned code to retrieve the column from the list called "Announcement"

it is working fine and giving me the desired result

but now i want to pass List name dynamically after deployment by user at run time instead of hard coded value of list name , so can any one help me altering this code :
C#
public partial class ContentSliderUserControl : UserControl
{
   string Qry = " <where><geq><fieldref name="Expires" /><value includetimevalue="FALSE" type="DateTime">{0}</value></geq></where>";
   protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           DisplayAnnouncements();
       }
   }


   private void DisplayAnnouncements()
   {
       SPSecurity.RunWithElevatedPrivileges(delegate()
         {
             using (SPSite site = new SPSite(SPContext.Current.Site.ID))
             {
                 using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
                 {
                     SPList list = web.Lists["Announcements"];
                     SPQuery query = new SPQuery();
                     query.RowLimit = 10;
                     query.Query = string.Format(Qry, DateTime.Now.ToString("yyyy-MM-dd"));
                     rep1.DataSource = list.GetItems(query).GetDataTable();
                     rep1.DataBind();
                 }
             }
         }
             );
   }
Posted
Updated 13-Sep-14 23:10pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900