Note:-
As this is a UserControl I am Not showing the HTML Code. For DropDown or RadioButtonList or CheckBox List Controls You have mention ID for DataValueField and Title for DataTextField if you want to insert data into the LookUp Column.
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Security;
namespace VisualWebPartProject1.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb currentWeb = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(currentWeb.Url))
{
using (SPWeb objWeb = site.OpenWeb())
{
SPList TasksList = objWeb.Lists["Tasks"];
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
SPListItemCollection myColl = TasksList.GetItems(query);
if (myColl.Count > 0)
{
sgvTasks.DataSource = myColl.GetDataTable();
sgvTasks.DataBind();
ddlTest.DataSource = myColl.GetDataTable();
ddlTest.DataBind();
ddlTest.Items.Insert(0, new ListItem("Select Task Name"));
chkTasks.DataSource = myColl.GetDataTable();
chkTasks.DataBind();
rblTasks.DataSource = myColl.GetDataTable();
rblTasks.DataBind();
}
}
}
});
}
}
}
As this is a UserControl I am Not showing the HTML Code. For DropDown or RadioButtonList or CheckBox List Controls You have mention ID for DataValueField and Title for DataTextField if you want to insert data into the LookUp Column.
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Security;
namespace VisualWebPartProject1.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb currentWeb = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(currentWeb.Url))
{
using (SPWeb objWeb = site.OpenWeb())
{
SPList TasksList = objWeb.Lists["Tasks"];
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
SPListItemCollection myColl = TasksList.GetItems(query);
if (myColl.Count > 0)
{
sgvTasks.DataSource = myColl.GetDataTable();
sgvTasks.DataBind();
ddlTest.DataSource = myColl.GetDataTable();
ddlTest.DataBind();
ddlTest.Items.Insert(0, new ListItem("Select Task Name"));
chkTasks.DataSource = myColl.GetDataTable();
chkTasks.DataBind();
rblTasks.DataSource = myColl.GetDataTable();
rblTasks.DataBind();
}
}
}
});
}
}
}
No comments:
Post a Comment