469,160 Members | 1,915 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,160 developers. It's quick & easy.

Gridview Problem

nitindel
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.:

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="gvOU" runat="server" AllowPaging="True" AllowSorting="True" 
  2.         AutoGenerateColumns="False" 
  3.         PageSize="5" Width="484px" onrowcommand="gvOU_RowCommand" 
  4.         onrowdatabound="gvOU_RowDataBound" onrowdeleting="gvOU_RowDeleting">
  5.         <Columns>
  6.         <asp:TemplateField headertext="Name" sortexpression="name" itemstyle-width="200" itemstyle-wrap="False">
  7.  
  8.    <headertemplate>
  9.  
  10.  <asp:LinkButton  id="btnName" commandargument="name" commandname="Sort" runat="server" Text="Name" />
  11.     <div style="display:inline; margin-left:220px"></div> 
  12.    </headertemplate>
  13.    <itemtemplate>
  14.     <asp:linkbutton commandname="Select" id="lnkName" runat="server"><%#DataBinder.Eval(Container.DataItem, "name").ToString()%></asp:linkbutton>              
  15.    </itemtemplate>
  16.  
  17. <ItemStyle Wrap="False" Width="200px"></ItemStyle>
  18.   </asp:TemplateField>
  19.  
  20. <asp:BoundField headertext="Level" datafield="level" visible="False" />
  21. <asp:BoundField headertext="LDAP Path" datafield="adspath" visible="False" />
  22. <asp:BoundField headertext="Category" datafield="objectCategory" visible="False" />
  23. <asp:BoundField headertext="Name" datafield="name" visible="false" />
  24.  
  25.  
  26.  
  27.             <asp:TemplateField HeaderText="Description">
  28.             <HeaderTemplate>
  29.             <asp:LinkButton id="btnDesc" commandargument="description" commandname="Sort" runat="server" Text="Description"/>
  30.             </HeaderTemplate>
  31.             <ItemTemplate>
  32.             <asp:Label ID="litDesc" runat="server"><%#DataBinder.Eval(Container.DataItem, "description").ToString()%></asp:Label>
  33.             </ItemTemplate>
  34.             </asp:TemplateField>
  35.             <asp:TemplateField HeaderText="Delete">
  36.             <ItemTemplate>
  37.             <asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" Text="Delete"></asp:LinkButton>
  38.  
  39.             </ItemTemplate>
  40.             </asp:TemplateField>

Also, my code behind that i have called for Gridview populate on page load is :

Expand|Select|Wrap|Line Numbers
  1.  DataTable dt;
  2.         CurrentContext con = (CurrentContext)Session["CurrentContext"];
  3.         CurrentUser cuser = (CurrentUser)Session["CurrentUser"];
  4.  
  5.         if (Session[Constants.KEY_ADSEARCHCACHE] != null)
  6.         {  //see if results are cached.
  7.             dt = (DataTable)Session[Constants.KEY_ADSEARCHCACHE];
  8.         }
  9.         else
  10.         { //get new results
  11.  
  12.             string filter = string.Empty;
  13.             ContextLevel level = ContextLevel.CustomerUser;
  14.  
  15.             switch (con.ContextLevel)
  16.             {  //get the correct filter for the different levels.
  17.                 case ContextLevel.HostingDomain:
  18.                     level = ContextLevel.Reseller;
  19.                     filter = "(|(objectClass=organizationalUnit)(&(objectcategory=person)(samaccountname=*)))";
  20.                     break;
  21.                 case ContextLevel.Reseller:
  22.                     level = ContextLevel.Customer;
  23.                     filter = "(|(objectClass=organizationalUnit)(&(objectcategory=person)(samaccountname=*)))";
  24.                     break;
  25.                 case ContextLevel.Customer:
  26.                     level = ContextLevel.CustomerUser;
  27.                     filter = "(&(objectcategory=person)(samaccountname=*))";
  28.                     break;
  29.             }
  30.  
  31.             string ldapPath = con.LDAPPath;
  32.  
  33.             DirectoryEntry de = new DirectoryEntry(ldapPath, cuser.Domain + @"\" + cuser.SamAccountName, cuser.Password, AuthenticationTypes.Secure);
  34.             DirectorySearcher ds = new DirectorySearcher(de, filter);
  35.  
  36.             //properties to load up
  37.             ds.PropertiesToLoad.Add("name");
  38.             ds.PropertiesToLoad.Add("adspath");
  39.             ds.PropertiesToLoad.Add("objectCategory");
  40.             ds.PropertiesToLoad.Add("description");
  41.             ds.PropertiesToLoad.Add("mail");
  42.             ds.PageSize = 100;
  43.             ds.SearchScope = SearchScope.OneLevel;
  44.  
  45.             //Get the AD listing.
  46.             SearchResultCollection results = ds.FindAll();
  47.  
  48.             dt = new DataTable();
  49.  
  50.             //Create columns from first search result.  Each property from results has its own column.
  51.             foreach (string key in ds.PropertiesToLoad)
  52.             {
  53.                 dt.Columns.Add(key);
  54.             }
  55.             //Add level column because its not a AD property.
  56.             dt.Columns.Add("Level");
  57.  
  58.             //create a new row for each result and each AD property
  59.             object[] newRow;
  60.             foreach (SearchResult result in results)
  61.             {
  62.                 newRow = new object[dt.Columns.Count];
  63.                 for (int i = 0; i < newRow.Length - 1; i++)
  64.                 {
  65.                     if (result.Properties[dt.Columns[i].ColumnName] == null)
  66.                     {//dont error if null, skip it.
  67.                         newRow[i] = string.Empty;
  68.                         continue;
  69.                     }
  70.                     if (result.Properties[dt.Columns[i].ColumnName].Count == 0) newRow[i] = string.Empty;
  71.                     else newRow[i] = result.Properties[dt.Columns[i].ColumnName][0];
  72.                 }
  73.                 newRow[dt.Columns.Count - 1] = level; //put level value in last column
  74.                 dt.Rows.Add(newRow);  //add the row to the table.
  75.             }
  76.  
  77.             //store in cache
  78.             Session.Add(Constants.KEY_ADSEARCHCACHE, dt);
  79.  
  80.         }
  81.  
  82.         //the dataview is bound to the grid.  It allows us to easily sort and search.
  83.         DataView dv = new DataView(dt);
  84.  
  85.         //search code.  Only search if a string was passed.
  86.         if (searchString != null && searchString != string.Empty) dv.RowFilter = "name like '%" + searchString + "%'";
  87.  
  88.  
  89.         //sort the results
  90.         string sortOrderValue;
  91.  
  92.         if (sortOrder)
  93.         {  //translate our bool sortorder into terms the dataview needs.
  94.             sortOrderValue = "ASC";
  95.  
  96.         }
  97.         else
  98.         {
  99.             sortOrderValue = "DESC";
  100.  
  101.         }
  102.  
  103.         _sortColumnName = sortColumnName;
  104.         dv.Sort = sortColumnName + " " + sortOrderValue;
  105.  
  106.         //bind
  107.         gvOU.DataSource = dv;
  108.         gvOU.DataBind(); </Columns>
  109.  
  110.  
  111.  
  112.     </asp:GridView>



Actually i want to Fetch the values of all cells when i click the Delete Button in the Gridview.





Thanks,

Nitin Sharma
Aug 11 '08 #1
1 1626
kenobewan
4,871 Expert 4TB
How about telling us what the error was and which line number threw it? Thanks.
Aug 11 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by NateDawg | last post: by
2 posts views Thread by Loading name... | last post: by
3 posts views Thread by Jeff | last post: by
2 posts views Thread by antonyliu2002 | last post: by
8 posts views Thread by =?Utf-8?B?TWlrZSBSYW5k?= | last post: by
1 post views Thread by Jeff | last post: by
11 posts views Thread by Ed Dror | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.