using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
namespace Saravanan_Testsolutions.Gridsamples
{
public partial class GridsamplesUserControl : UserControl
{
public SPList olist { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
databind();
}
public void databind()
{
try
{
using(SPSite osite= new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb oweb = osite.OpenWeb(SPContext.Current.Web.Name))
{
olist = oweb.Lists.TryGetList("Tasks");
SPListItemCollection oitemcoll = olist.Items;
if (oitemcoll.Count > 0)
{
grdshow.DataSource = oitemcoll.GetDataTable();
grdshow.DataBind();
}
}
}
}
catch (Exception)
{
throw;
}
}
protected void grdshow_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink lnk = new HyperLink();
lnk.Text = e.Row.Cells[0].Text;
lnk.NavigateUrl =olist.DefaultViewUrl;
e.Row.Cells[0].Controls.Add((Control)lnk);
}
}
}
}
No comments:
Post a Comment