473,692 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview Problem

nitindel
67 New Member
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 1844
kenobewan
4,871 Recognized Expert Specialist
How about telling us what the error was and which line number threw it? Thanks.
Aug 11 '08 #2

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

Similar topics

8
5033
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for my GridView/SqlDataSource combinations. I typically select from a view and update the corresponding...
3
13744
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
2
429
by: Loading name... | last post by:
Hey asp.net 2.0 I have a GridView on my webpage. This GridView's datasource is a SqlDataSource. The SqlDataSource returns 3 columns. Here is my problem: My GridView consist of 3 columns (id column + 2 text columns). I want to hide the id column, and change the formating of the text columns. I've tryed
3
4600
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a datasource to this GridView in runtime. But I cannot
2
13189
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
8
9657
by: =?Utf-8?B?TWlrZSBSYW5k?= | last post by:
I am trying to get a list of files from a specified directory using the System.IO namespace classes, and then use that list as the datasource for a GridView. I have been able to do this successfully. The problem is when I try to hook up a HyperLinkField it's not working. Basically, what I want to end up with is to have the file name listed in the column and have the link point to the full file path, for each file in the list. I've been...
1
6726
by: Jeff | last post by:
ASP.NET 2.0 I've got problems with the right column in my GridView. The GridView consist of 2 columns, the problem column is the column on the right side. The problem is that it looks like there is a huge space between the 2 columns, see the huge grey space between the 2 columns. I want the columns to be very close to each other with only 10px open space between the columns. Now it looks like there is a 160px margin between them
2
2824
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
6
5750
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the OnSelectedIndexChanged event set on it. This triggers just fine, but within the codebehind of the OnSelectedIndexChanged event, I need to scan through all the entries in the nested GridView (to see if the user changed a value to an already existing value in the...
11
4073
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved, CrtdUser and Date And Edit and Delete buttons
0
8544
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9090
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8810
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6462
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5821
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2977
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.