OutPut:-
.Ascx File for CheckBoxList
<asp:CheckBoxList ID="chkArticles" runat="server" RepeatDirection="Horizontal" DataValueField="Title" DataTextField="Title" RepeatColumns="2"></asp:CheckBoxList>
Code to Bind Data for CheckBoxList in .Ascx.cs file
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lstArticles = currentWeb.Lists["Articles"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy>";
sQuery.ViewFields = "<FieldRef Name='Title' />";
sQuery.ViewFieldsOnly = true;
SPListItemCollection myColl = lstArticles.GetItems(sQuery);
if (myColl.Count > 0)
{
chkArticles.DataSource = myColl.GetDataTable();
chkArticles.DataBind();
}
});
.Ascx file for RadioButtonList
<asp:RadioButtonList ID="rblArticles" runat="server" RepeatDirection="Horizontal" DataValueField="Title" DataTextField="Title" RepeatColumns="2"></asp:RadioButtonList>
Code to Bind Data for RadioButtonList in .Ascx.cs file
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lstArticles = currentWeb.Lists["Articles"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy>";
sQuery.ViewFields = "<FieldRef Name='Title' />";
sQuery.ViewFieldsOnly = true;
SPListItemCollection myColl = lstArticles.GetItems(sQuery);
if (myColl.Count > 0)
{
rblArticles.DataSource = myColl.GetDataTable();
rblArticles.DataBind();
}
});
.Ascx File for CheckBoxList
<asp:CheckBoxList ID="chkArticles" runat="server" RepeatDirection="Horizontal" DataValueField="Title" DataTextField="Title" RepeatColumns="2"></asp:CheckBoxList>
Code to Bind Data for CheckBoxList in .Ascx.cs file
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lstArticles = currentWeb.Lists["Articles"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy>";
sQuery.ViewFields = "<FieldRef Name='Title' />";
sQuery.ViewFieldsOnly = true;
SPListItemCollection myColl = lstArticles.GetItems(sQuery);
if (myColl.Count > 0)
{
chkArticles.DataSource = myColl.GetDataTable();
chkArticles.DataBind();
}
});
.Ascx file for RadioButtonList
<asp:RadioButtonList ID="rblArticles" runat="server" RepeatDirection="Horizontal" DataValueField="Title" DataTextField="Title" RepeatColumns="2"></asp:RadioButtonList>
Code to Bind Data for RadioButtonList in .Ascx.cs file
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lstArticles = currentWeb.Lists["Articles"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy>";
sQuery.ViewFields = "<FieldRef Name='Title' />";
sQuery.ViewFieldsOnly = true;
SPListItemCollection myColl = lstArticles.GetItems(sQuery);
if (myColl.Count > 0)
{
rblArticles.DataSource = myColl.GetDataTable();
rblArticles.DataBind();
}
});
No comments:
Post a Comment