H
Hai Nguyen
Below is my code, would anybody please figure out why it did not display any thing. The database did not anything in there yet, what it does is the header field. It just shows me the headers only, all the textboxes gone.
I want to have at least 5 rows which contain a textbox in each field. I don't know why, please help me
ALl textboxes gone ....
Thanks
public class gridform : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btsave;
protected System.Web.UI.WebControls.DataGrid datagrid;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
LoadData();
UpdateView();
}
}
private void LoadData()
{
string mystrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("dcpols.mdb");
OleDbConnection conn = new OleDbConnection(mystrConn);
Session["QuestionKey"] = 9;
string mystrCmd1 = "SELECT * FROM tblLightingEntry "; //not for retrieving data, it's just to get the headers for the // datagrids
OleDbDataAdapter da = new OleDbDataAdapter(mystrCmd1, conn);
DataSet ds = new DataSet();
da.Fill(ds, "MyQLookupTable");
Session["MyData"] = ds;
}
private void UpdateView()
{
DataSet ds = (DataSet) Session["MyData"];
//onLoadData();
// Bind the data
datagrid.DataSource = ds.Tables["MyQLookupTable"];
// Display the data
datagrid.DataBind();
}
private ArrayList getHeader()
{
DataSet ds = (DataSet)Session["MyData"];
DataTable dt = ds.Tables["MyQLookupTable"];
ArrayList qKeyList = new ArrayList();
foreach(DataRow dr in dt.Rows)
{
qKeyList.Add(dr["Q_Question"].ToString());
}
return qKeyList;
}
public void goSave(object sender,System.EventArgs e)
{
}
------------------------------------
<form id="Form1" method="post" runat="server">
<asp:datagrid id="datagrid" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 56px" runat="server"
AutoGenerateColumns="False" CellPadding="4" BackColor="White" BorderWidth="1px" BorderStyle="None"
BorderColor="#CC9966" OnItemCreated="ItemCreated" ShowFooter="True" >
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
<Columns>
<asp:TemplateColumn HeaderText="# of Fixtures" >
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:linkbutton runat="server" id="btnNewRow" onclick="AddNewRow" Text="Add new row..." />
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Watt/fix before">
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Watt/fix after">
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Controller Type w hr/s day">
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="hrs/day of timer use">
<ItemTemplate>
<asp:TextBox Runat="server" ID="Textbox1"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
I want to have at least 5 rows which contain a textbox in each field. I don't know why, please help me
ALl textboxes gone ....
Thanks
public class gridform : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btsave;
protected System.Web.UI.WebControls.DataGrid datagrid;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
LoadData();
UpdateView();
}
}
private void LoadData()
{
string mystrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("dcpols.mdb");
OleDbConnection conn = new OleDbConnection(mystrConn);
Session["QuestionKey"] = 9;
string mystrCmd1 = "SELECT * FROM tblLightingEntry "; //not for retrieving data, it's just to get the headers for the // datagrids
OleDbDataAdapter da = new OleDbDataAdapter(mystrCmd1, conn);
DataSet ds = new DataSet();
da.Fill(ds, "MyQLookupTable");
Session["MyData"] = ds;
}
private void UpdateView()
{
DataSet ds = (DataSet) Session["MyData"];
//onLoadData();
// Bind the data
datagrid.DataSource = ds.Tables["MyQLookupTable"];
// Display the data
datagrid.DataBind();
}
private ArrayList getHeader()
{
DataSet ds = (DataSet)Session["MyData"];
DataTable dt = ds.Tables["MyQLookupTable"];
ArrayList qKeyList = new ArrayList();
foreach(DataRow dr in dt.Rows)
{
qKeyList.Add(dr["Q_Question"].ToString());
}
return qKeyList;
}
public void goSave(object sender,System.EventArgs e)
{
}
------------------------------------
<form id="Form1" method="post" runat="server">
<asp:datagrid id="datagrid" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 56px" runat="server"
AutoGenerateColumns="False" CellPadding="4" BackColor="White" BorderWidth="1px" BorderStyle="None"
BorderColor="#CC9966" OnItemCreated="ItemCreated" ShowFooter="True" >
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
<Columns>
<asp:TemplateColumn HeaderText="# of Fixtures" >
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:linkbutton runat="server" id="btnNewRow" onclick="AddNewRow" Text="Add new row..." />
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Watt/fix before">
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Watt/fix after">
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Controller Type w hr/s day">
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="hrs/day of timer use">
<ItemTemplate>
<asp:TextBox Runat="server" ID="Textbox1"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>