473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to bind Datagrid?

hi everyone,
i have my datagrid populated with my Dataset
like
DataGrid1.DataSource=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(send_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 1162
xwero
99
hi everyone,
i have my datagrid populated with my Dataset
like
DataGrid1.DataSource=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(send_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
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...
2
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
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...
6
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...
3
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...
1
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
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...
7
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...
17
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...
3
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...

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.