473,769 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to bind Datagrid?

27 New Member
hi everyone,
i have my datagrid populated with my Dataset
like
DataGrid1.DataS ource=Dataset1;
this data set contains the value of count the total of email sent ,receive and deliver for a particular user id now i want to display user id with taht data but i dont have user name in my dataset because i can not write query like

select uname,count(sen d_email) from table where uname="ABCD";

because here i used aggregate function
...here i m selecting the user name from listbox so the query will saw the count of send ,receive and etc information for that user.now i want to display the user name in Datagrid that i selected from listbox so how can i add that valu or column to datgrid
Regards........ ...........
Ripen
Feb 26 '07 #1
1 1176
xwero
99 New Member
hi everyone,
i have my datagrid populated with my Dataset
like
DataGrid1.DataS ource=Dataset1;
this data set contains the value of count the total of email sent ,receive and deliver for a particular user id now i want to display user id with taht data but i dont have user name in my dataset because i can not write query like

select uname,count(sen d_email) from table where uname="ABCD";

because here i used aggregate function
...here i m selecting the user name from listbox so the query will saw the count of send ,receive and etc information for that user.now i want to display the user name in Datagrid that i selected from listbox so how can i add that valu or column to datgrid
Regards........ ...........
Ripen
As i understand from your explaination you want to add the username to all of your rows. This can be done with the OnItemDataBound . I assume you add a new column to your datagrid and you use a literal with the id: username. The OnItemDataBound attribute is a part of the asp:Datagrid tag and the value is a function, lets say dataBound.

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#"  %>
  2.  
  3. <script runat="server">
  4. void dataBound(Object sender, DataGridItemEventArgs e)
  5.     {
  6.         // get bound data + database connection
  7.         DataRowView row = (DataRowView)e.Item.DataItem;
  8.         OdbcConnection conn = new OdbcConnection(ConfigurationSettings.AppSettings["connString"]);
  9.         // for edit templates
  10.         if (e.Item.ItemType == ListItemType.EditItem)
  11.         {
  12.             // if it's the same code you best put it another function and call that.
  13.             string sql = "select uname,count(send_email) from table where uname=?";
  14.             OdbcCommand com = new OdbcCommand(sql, conn);
  15.             com.Parameters.Add("", OdbcType.Int, 10).Value = Convert.ToInt32(row["id"]);
  16.             // and so on
  17.        }
  18.         // for other templates
  19.         else if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
  20.         {
  21.  
  22.          }
  23. }
  24. </script>
  25. <ASP:DataGrid id="DataGrid1" runat="server" 
  26.         OnItemDataBound="dataBound"
  27.         AutoGenerateColumns="false"
  28.       >
  29. <!-- other columns -->
  30. <asp:TemplateColumn HeaderText="Username">
  31.                 <ItemTemplate><asp:Literal id="username" runat="server" /></ItemTemplate>
  32.                 <EditItemTemplate>
  33.                     <h3>Ingeschreven</h3>
  34.                     <asp:Literal id="usernameedit" runat="server" />
  35.                 </EditItemTemplate>
  36.             </asp:TemplateColumn>
  37. <!-- other columns -->
  38.  
Sorry i haven't much time now but i think you can get the intention.
Feb 26 '07 #2

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

Similar topics

2
2100
by: Pete Nelson | last post by:
Does anyone know of a way to bind a string collection to a datagrid? Basically, I have an object, CreditPlans, and a string collection, ModelNumbers. I'd like to bind the ModelNumbers collection to the datagrid, but because there isn't a custom object with properties, just a string object, I'm not sure how to reference it in the datagrid. FYI, I can enumerate through the collection... foreach(string modelNum in...
2
2796
by: Vijaya | last post by:
Can we bind data to textbox in a headertemplate in a template column of a datagrid? If so please give some code snippets. Thank you
4
4090
by: Greg Linwood | last post by:
I am wondering what the best approach to binding XML data to an asp:Table from the Page_Load event in a code behind module? I'm using VB.Net and initially approached this by adding a table to the web page from the VS2003 ASP page designer, extracting an XML document from SQL Server during Page_Load, then adding asp:TableRows & asp:TableCells one at a time / loading the corresponding xml values a cell at a time. Is there a better (less...
6
5323
by: coleenholley | last post by:
I have a Class Module written in VB that calls an RPC (written in COBOL) we have written code to read the data from the RPC, and we create a temporary datatable to store the data from the RPC. This works fine when we call the datatable and bind it to a data grid using datagridname.DataBind(), but I have an ASP table, with calculations using tbl_name.row(1).cells(1) and the result of the calculation is put in a specific row and cell. I have...
3
2327
by: AFN | last post by:
I need to manually create the data to be shown in a datagrid (or some data table object). Should I create an array and bind the array to the datagrid OR should I create a temporary dataset and bind that to the datagrid? I have never done either (usually I get a recordset from a stored procedure and bind results directly). I also don't know which is faster. Whichever you suggest, can you give a couple lines of sample code? Thank...
1
1283
by: suresh_C# | last post by:
Hi All, I want to bind datagrid with 3 different datatables. Please tell me what is a right way of doing that. Any help will be appreciated. Thanks, Mahesh
2
2208
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple properties, ProdID, Description, Quantity and UPC. 3 strings and a long. The LineItemsCollection class inherits from System.Collections.Specialized.NameObjectCollectionBase. It also implements both IEnumerable and IList.
7
2563
by: Jed | last post by:
I have a web service method that returns an array of custom objects marked serializeable with fully described public properties. When I bind the results to a DataGrid I can access the properties in the ItemDataBound event of the codebehind but I can't access them declaratively in the HTML code? Here is the code to call the method. net.mysite.www.WSInterface proxy; proxy = new net.mysite.www.WSInterface();
17
2770
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only allow user to filter the first time, when they tried the second time, the speficied cast error message will prompt one.... I create a mydataset1 first, and the mydataset1 data source was getting from DataGrid.DataSource.
3
3291
by: serge calderara | last post by:
Dear all, Does anyone know how to bind a System.Collection.ArraysList object to a Dataset ? Thanks for your reply Regards Serge
0
9416
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
10199
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
9981
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
9850
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
8862
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
7396
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
6662
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
5436
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3948
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.