473,468 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datagrid problems

I have two columns

Question Answers
Q1
Q2
Q3
Q4

Submit

I have the following code to collect the answers and update them in the
database but I got the error. I don't know what to do, please tell me if you
can

Thanks



public void updateQuestion(object sender,System.EventArgs e)

{

ArrayList myAnsList = new ArrayList();

foreach(DataGridItem dataGridItem in grid.Items)

{

string str = ((TextBox)grid.FindControl("answerbox")).Text; ->error

myAnsList.Add(str);

}

//update

loadProDataTalbe(myAnsList);

}

<asp:datagrid id="grid" runat="server" >
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#9471DE"></SelectedItemStyle>
<ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#E7E7FF"
BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
<PagerStyle HorizontalAlign="Right" ForeColor="Black"
BackColor="#C6C3C6"></PagerStyle>
<Columns>
<asp:BoundColumn DataField="Q_Question"
HeaderText="Questions"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:TextBox Runat="server" ID="answerbox"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 100: foreach(DataGridItem dataGridItem in grid.Items)
Line 101: {
Line 102: string str = ((TextBox)grid.FindControl("answerbox")).Text;
Line 103: myAnsList.Add(str);
Line 104: }
Nov 18 '05 #1
2 1121
Douglas,
Looks like you need to check the ListItemType before
your loop. The DateGrid.Items collection holds the Header
and Footer items as well as the data that you are interest
in testing. The code is blowing up on the
ListItemType.Header and will do the same when it gets down
to the ListItemType.Footer because those datagrid rows
don't contain the textbox controls.
Barry.
-----Original Message-----
I have two columns

Question Answers
Q1
Q2
Q3
Q4

Submit

I have the following code to collect the answers and update them in thedatabase but I got the error. I don't know what to do, please tell me if youcan

Thanks



public void updateQuestion(object sender,System.EventArgs e)
{

ArrayList myAnsList = new ArrayList();

foreach(DataGridItem dataGridItem in grid.Items)

{

string str = ((TextBox)grid.FindControl ("answerbox")).Text; ->error
myAnsList.Add(str);

}

//update

loadProDataTalbe(myAnsList);

}

<asp:datagrid id="grid" runat="server" >
<SelectedItemStyle Font-Bold="True" ForeColor="White"BackColor="#9471DE"></SelectedItemStyle>
<ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#E7E7FF"
BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle> <PagerStyle HorizontalAlign="Right" ForeColor="Black"BackColor="#C6C3C6"></PagerStyle>
<Columns>
<asp:BoundColumn DataField="Q_Question"
HeaderText="Questions"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:TextBox Runat="server" ID="answerbox"></asp:TextBox> </ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of thecurrent web request. Please review the stack trace for more informationabout the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not setto an instance of an object.

Source Error:

Line 100: foreach(DataGridItem dataGridItem in grid.Items)Line 101: {
Line 102: string str = ((TextBox)grid.FindControl("answerbox")).Text;Line 103: myAnsList.Add(str);
Line 104: }
.

Nov 18 '05 #2
You are right, I have it fixed Now i want to store all the ansers users type
in those boxes and store it somewhere. I could not get those answers

Thank for your help

"Douglas Gage" <ha******@neo.tamu.edu> wrote in message
news:Oa*************@TK2MSFTNGP11.phx.gbl...
I have two columns

Question Answers
Q1
Q2
Q3
Q4

Submit

I have the following code to collect the answers and update them in the
database but I got the error. I don't know what to do, please tell me if you can

Thanks



public void updateQuestion(object sender,System.EventArgs e)

{

ArrayList myAnsList = new ArrayList();

foreach(DataGridItem dataGridItem in grid.Items)

{

string str = ((TextBox)grid.FindControl("answerbox")).Text; ->error
myAnsList.Add(str);

}

//update

loadProDataTalbe(myAnsList);

}

<asp:datagrid id="grid" runat="server" >
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#9471DE"></SelectedItemStyle>
<ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#E7E7FF"
BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
<PagerStyle HorizontalAlign="Right" ForeColor="Black"
BackColor="#C6C3C6"></PagerStyle>
<Columns>
<asp:BoundColumn DataField="Q_Question"
HeaderText="Questions"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:TextBox Runat="server" ID="answerbox"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 100: foreach(DataGridItem dataGridItem in grid.Items)
Line 101: {
Line 102: string str = ((TextBox)grid.FindControl("answerbox")).Text;
Line 103: myAnsList.Add(str);
Line 104: }

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Lina | last post by:
Hi, Can anyone tell me if it is possible to add link buttons to a datagrid that has its source set to a datatable that i have created? i.e i want the user to be able to select a room from...
2
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
3
by: Igor Mendizabal | last post by:
Hello, We're doing our own datagrid based on the System.windows.forms.datagrid control, and are having some problems with horizontal scrolling. In general, we construct our datagrid adding a...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
0
by: THM5101 | last post by:
Hello I have two problems with my dataGrid. I created dataGrid with 4 columns. The first and the last one are LinkButton type, the second and third are Bound Column type. My problems are:...
5
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes,...
0
by: Linus | last post by:
Hi, I have a datagrid nested inside another datagrid, the edit/update/cancel command works fine on the outter datagrid but I'm having problems with the inner one. There are 2 problems and here's...
3
by: nkunkov | last post by:
Hi, I have read a lot of articles in this newsgroup about how to solve this problem but found no solution. I'm trying to export a C# datagrid to Excel file. Here is my code that I have also...
3
by: simchajoy2000 | last post by:
Hi, I have been working with datagrids a lot in the past two weeks and I am running across a lot of problems. Maybe there is no way around these problems but I hope there are and someone out...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
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...
1
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...
0
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,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.