How to get contents out of datagrid

D

Douglas Gage

How to get contents out of datagrid? I have fixed the problem before but now when i debug I could not see any thing in the text box


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

{

ArrayList myAnsList = new ArrayList();

foreach(DataGridItem item in grid.Items)

{

TextBox ans = (TextBox)item.FindControl("answerbox");


myAnsList.Add(ans.Text.ToString()); ///ans.Text -> there is nothing here?

}

//update

loadProDataTalbe(myAnsList);

}









<asp:datagrid id="grid" runat="server" Width="608px" OnItemCreated="ItemCreated" AutoGenerateColumns="False"
CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" BorderWidth="2px" BorderStyle="Ridge" BorderColor="White" ShowFooter="True">
<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>
 
C

Craig Deelsnyder

Douglas said:
How to get contents out of datagrid? I have fixed the problem before but
now when i debug I could not see any thing in the text box



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

{

ArrayList myAnsList = new ArrayList();

foreach(DataGridItem item in grid.Items)

{

TextBox ans = (TextBox)item.FindControl("answerbox");

myAnsList.Add(ans.Text.ToString()); ///ans.Text -> there is nothing here?

}

//update

loadProDataTalbe(myAnsList);

}

Um, looks OK at first glance to me. I would think you'd get a null
reference before this 'problem'....are you sure you're not rebinding the
grid each time the page loads (in Page_Load)? Only bind it if
!IsPostBack.....that may cause this, not sure....
 
D

Douglas Gage

You are wonderful !!!!

Thanks a bunch


Craig Deelsnyder said:
Um, looks OK at first glance to me. I would think you'd get a null
reference before this 'problem'....are you sure you're not rebinding the
grid each time the page loads (in Page_Load)? Only bind it if
!IsPostBack.....that may cause this, not sure....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top