473,659 Members | 2,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

My Datagrid is not binding all columns

7 New Member
Hello frnds,

I have created a datagrid with the following code......
Expand|Select|Wrap|Line Numbers
  1.  
  2. <asp:datagrid id="DataGrid1" BackColor="#ccccff" BorderColor="black" Width="750" Runat="server" AutoGenerateColumns="False" HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" Font-Name="Verdana" CellSpacing="0" CellPadding="3" ShowFooter="True" GridLines="None" OnItemDataBound="Datagrid1_itemdataBound">
  3. <Columns>
  4. <asp:TemplateColumn HeaderText="S.No."></asp:TemplateColumn>
  5. <asp:TemplateColumn HeaderText="Select">
  6. <ItemTemplate>
  7. <asp:CheckBox ID="checkbox1" Runat="server" Checked="False"></asp:CheckBox>
  8. </ItemTemplate>
  9. </asp:TemplateColumn>
  10. <asp:BoundColumn HeaderText="BookId" DataField="BookId" Visible="true"></asp:BoundColumn>
  11. <asp:BoundColumn HeaderText="CatId" DataField="CatId" Visible="true"></asp:BoundColumn>
  12. <asp:BoundColumn HeaderText="Book Name" DataField="Title"></asp:BoundColumn>
  13. <asp:BoundColumn HeaderText="Author" DataField="Author"></asp:BoundColumn>
  14. <asp:BoundColumn HeaderText="Publisher" DataField="Publisher"></asp:BoundColumn>
  15. <asp:BoundColumn HeaderText="Price" DataField="Price" DataFormatString="{0:c}"></asp:BoundColumn>
  16. <asp:BoundColumn HeaderText="Quantity" DataField="Quantity"></asp:BoundColumn>
  17. <asp:BoundColumn HeaderText="Category" DataField="CatName"></asp:BoundColumn>
  18. </Columns>
  19. </asp:datagrid>
The datagrid is bind with the database on button click event......

Expand|Select|Wrap|Line Numbers
  1. sub button1_click(sender as object,e as eventargs) 
  2.     dim book as string 
  3.     dim ctr as integer
  4.     dim con as sqlconnection
  5.     'dim cmd as sqlcommand
  6.     dim da as sqldataadapter
  7.     dim ds as dataset
  8.     dim str as string
  9.     book=txt1.text.toupper()
  10.     cat=dropdownlist1.selectedvalue
  11.  
  12.     'response.write(book)
  13.     ctr=integer.parse(cat)
  14.     'response.write(ctr.tostring())
  15.     str="server=WADHWA;user id=sa;pwd=;initial catalog=OnlineShoppingDatabase"
  16.     con=new SqlConnection(str)
  17.     con.open()
  18.     'str="select bookdetails.catid , bookdetails.Title,bookdetails.author,bookdetails.publisher,bookdetails.price,bookdetails.quantity,CategDetails.CatName from bookdetails inner join categDetails  on CategDetails.catid= bookdetails.catid where bookdetails.title='" & txt1.text.toupper & "' and CategDetails.catid=" & dropdownlist1.selectedvalue
  19.     str="select bookdetails.bookId,bookdetails.CatId,bookdetails.Title,bookdetails.author,bookdetails.publisher,bookdetails.price,bookdetails.quantity,CategDetails.CatName from bookdetails inner join categDetails  on CategDetails.catid= bookdetails.catid where bookdetails.title like '%" & txt1.text.toupper & "%' and CategDetails.catid=" & dropdownlist1.selectedvalue
  20.     da=new SqlDataAdapter()
  21.     da.selectcommand=new SqlCommand()
  22.     da.selectcommand.connection=con
  23.     da.selectcommand.commandtext=str
  24.     ds=new DataSet
  25.     da.fill(ds)
  26.     response.write(ds.tables(0).columns.count.tostring())
  27.     if ds.tables(0).rows.count =0 then
  28.     ' datagrid1.datasource=ds
  29.     'datagrid1.databind()
  30.     'response.redirect("webform5.aspx")
  31.     response.write("No Matches found")
  32.     else
  33.     Panel1.visible=true
  34.     datagrid1.datasource=ds
  35.     datagrid1.databind()
  36.     end if
  37.     con.close()
  38.     end sub
In this code section,I have used a join query.There are two tables
BookDetails with fields(bookid,c atid,title,auth or,publisher,pr ice,quantity) and CategDetails with fields(catid,ca tname).

Now when i display the total number of columns bind with datagrid is only 6 but it has to bind 8 columns (bookid,catid,t itle,author,pub lisher,price,qu antity,catname respectively),w ith this following code :-
Expand|Select|Wrap|Line Numbers
  1. Response.write(Datagrid1.items.count.tostring) 
Please why its happening.is there any miscoded by me ????
Feb 22 '07 #1
1 1266
enreil
86 New Member
Can you determine by their contents which columns are not getting bound?
Feb 22 '07 #2

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

Similar topics

8
7904
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the same control. Is there anyone who has tried this before and knows why this is hapenning ??
5
2586
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order date, name, address etc) about the selected row in the datagrid... My problem is when I enter a new record in the details tabpage (saves data to database), and go back to the datagrid. Only the data from the PM-table
4
2830
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the form/grid first opens up and the grid is immediately sorted the TB don't reflect the sorted data of the First row of the grid. Note: Initially the black grid indicator arrow points to the first row. If the user choses another row and then sorts...
0
3492
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the full code for the test below. Create a project drop in the code and run. There is nothing crazy about the code. I used the designer to add the dataset and to do the...
3
4871
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
8
3921
by: Richard L Rosenheim | last post by:
I have a dataset containing a parent table related to a child table. The child table contains an ID field (which is configured as autonumber in the datatable), the ID of the parent, plus some addition fields. I'm able to get the datagrid to be properly populate with only the child records relating to the specified parent by setting the ..DefaultView.RowFilter property. Currently, to properly add a new child record, I need to manually...
4
2279
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a combobox in a datagrid? Any other suggestions/articles on how to implement many-many relations in the frontend (which of course are 2 one-many relations)?
6
5737
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid to a DataSet. If i include an if statement to prevent the data binding from occuring on a page PostBack in the following way:
7
3551
by: Arpan | last post by:
Assume that a database table has the following 4 columns - ID, UserID, Subject & Marks. I am retrieving the records existing in this DB table & displaying them in a DataGrid like this: <script runat="server"> Sub Page_Load(obj As Object, ea As EventArgs) Dim dSet As DataSet Dim sqlConn As SqlConnection Dim sqlDapter As SqlDataAdapter
2
6582
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click in the child datagrid and then go to the combobox and choose another vendor. When the new vendor is loaded nothing shows in the datagrid but the itemsource shows the info is there. Know if I click on the child cell and then click back on the...
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
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,...
1
8528
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,...
1
6179
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
5649
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
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2752
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
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.