Hi All,
Please tell me any good site for Gridview control.(not for datagrid).
I am facing error in fetching the values of the Bound columns in the gridview:
lease tell me how should i fetch the value..of a bound column..??
Below is the code.:
Also, my code behind that i have called for Gridview populate on page load is :
Actually i want to Fetch the values of all cells when i click the Delete Button in the Gridview.
Thanks,
Nitin Sharma
Please tell me any good site for Gridview control.(not for datagrid).
I am facing error in fetching the values of the Bound columns in the gridview:
lease tell me how should i fetch the value..of a bound column..??
Below is the code.:
Code:
<asp:GridView ID="gvOU" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False"
PageSize="5" Width="484px" onrowcommand="gvOU_RowCommand"
onrowdatabound="gvOU_RowDataBound" onrowdeleting="gvOU_RowDeleting">
<Columns>
<asp:TemplateField headertext="Name" sortexpression="name" itemstyle-width="200" itemstyle-wrap="False">
<headertemplate>
<asp:LinkButton id="btnName" commandargument="name" commandname="Sort" runat="server" Text="Name" />
<div style="display:inline; margin-left:220px"></div>
</headertemplate>
<itemtemplate>
<asp:linkbutton commandname="Select" id="lnkName" runat="server"><%#DataBinder.Eval(Container.DataItem, "name").ToString()%></asp:linkbutton>
</itemtemplate>
<ItemStyle Wrap="False" Width="200px"></ItemStyle>
</asp:TemplateField>
<asp:BoundField headertext="Level" datafield="level" visible="False" />
<asp:BoundField headertext="LDAP Path" datafield="adspath" visible="False" />
<asp:BoundField headertext="Category" datafield="objectCategory" visible="False" />
<asp:BoundField headertext="Name" datafield="name" visible="false" />
<asp:TemplateField HeaderText="Description">
<HeaderTemplate>
<asp:LinkButton id="btnDesc" commandargument="description" commandname="Sort" runat="server" Text="Description"/>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="litDesc" runat="server"><%#DataBinder.Eval(Container.DataItem, "description").ToString()%></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Also, my code behind that i have called for Gridview populate on page load is :
Code:
DataTable dt;
CurrentContext con = (CurrentContext)Session["CurrentContext"];
CurrentUser cuser = (CurrentUser)Session["CurrentUser"];
if (Session[Constants.KEY_ADSEARCHCACHE] != null)
{ //see if results are cached.
dt = (DataTable)Session[Constants.KEY_ADSEARCHCACHE];
}
else
{ //get new results
string filter = string.Empty;
ContextLevel level = ContextLevel.CustomerUser;
switch (con.ContextLevel)
{ //get the correct filter for the different levels.
case ContextLevel.HostingDomain:
level = ContextLevel.Reseller;
filter = "(|(objectClass=organizationalUnit)(&(objectcategory=person)(samaccountname=*)))";
break;
case ContextLevel.Reseller:
level = ContextLevel.Customer;
filter = "(|(objectClass=organizationalUnit)(&(objectcategory=person)(samaccountname=*)))";
break;
case ContextLevel.Customer:
level = ContextLevel.CustomerUser;
filter = "(&(objectcategory=person)(samaccountname=*))";
break;
}
string ldapPath = con.LDAPPath;
DirectoryEntry de = new DirectoryEntry(ldapPath, cuser.Domain + @"\" + cuser.SamAccountName, cuser.Password, AuthenticationTypes.Secure);
DirectorySearcher ds = new DirectorySearcher(de, filter);
//properties to load up
ds.PropertiesToLoad.Add("name");
ds.PropertiesToLoad.Add("adspath");
ds.PropertiesToLoad.Add("objectCategory");
ds.PropertiesToLoad.Add("description");
ds.PropertiesToLoad.Add("mail");
ds.PageSize = 100;
ds.SearchScope = SearchScope.OneLevel;
//Get the AD listing.
SearchResultCollection results = ds.FindAll();
dt = new DataTable();
//Create columns from first search result. Each property from results has its own column.
foreach (string key in ds.PropertiesToLoad)
{
dt.Columns.Add(key);
}
//Add level column because its not a AD property.
dt.Columns.Add("Level");
//create a new row for each result and each AD property
object[] newRow;
foreach (SearchResult result in results)
{
newRow = new object[dt.Columns.Count];
for (int i = 0; i < newRow.Length - 1; i++)
{
if (result.Properties[dt.Columns[i].ColumnName] == null)
{//dont error if null, skip it.
newRow[i] = string.Empty;
continue;
}
if (result.Properties[dt.Columns[i].ColumnName].Count == 0) newRow[i] = string.Empty;
else newRow[i] = result.Properties[dt.Columns[i].ColumnName][0];
}
newRow[dt.Columns.Count - 1] = level; //put level value in last column
dt.Rows.Add(newRow); //add the row to the table.
}
//store in cache
Session.Add(Constants.KEY_ADSEARCHCACHE, dt);
}
//the dataview is bound to the grid. It allows us to easily sort and search.
DataView dv = new DataView(dt);
//search code. Only search if a string was passed.
if (searchString != null && searchString != string.Empty) dv.RowFilter = "name like '%" + searchString + "%'";
//sort the results
string sortOrderValue;
if (sortOrder)
{ //translate our bool sortorder into terms the dataview needs.
sortOrderValue = "ASC";
}
else
{
sortOrderValue = "DESC";
}
_sortColumnName = sortColumnName;
dv.Sort = sortColumnName + " " + sortOrderValue;
//bind
gvOU.DataSource = dv;
gvOU.DataBind(); </Columns>
</asp:GridView>
Actually i want to Fetch the values of all cells when i click the Delete Button in the Gridview.
Thanks,
Nitin Sharma
Comment