|
-
Jan 15th, 2004, 02:21 AM
#1
Thread Starter
Junior Member
Datagrid Help???
Hi all
I'm trying to create form (can be anything, but a prefer it's a datagrid).
It should look like this
Header 1 Header 2 Header3 Header4 Header5
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
(textbox) (textbox) (textbox) (textbox)
(textbox)
My question is:
1/ Since I don't know the number of row in advance, if I'm still be able to
generate datagrid with a particular number of row (let's say 10 rows)
2/ Because the header is stored in a ArrayList, how do i bind those to the
header
3/ After user fills out those textbox, I need to insert those infos to
database, how can I do that?
4/ If users want to insert more than the rows printing, how can they add
more rows?
I appreciate any idea to get this problem solve.
PS: If we can n't solve in datagrid, any solutions will be my big help
Thanks everyone
-
Jan 15th, 2004, 08:58 AM
#2
Member
what kind of application do you want to make. Because otherwise just use the edit options of the datagrid.
-
Jan 15th, 2004, 09:07 AM
#3
Thread Starter
Junior Member
Datagrid
It's web form application
I don't know if I can build it form ItemHandler. I've never tried and I'm clueless
Thanks
-
Jan 15th, 2004, 09:33 AM
#4
PowerPoster
If this isn't going to be bound to a datasource, which it looks like it isn't, then you should probably look into the table contol. Basically you just create row objects, put what ever cell objects in the row you need, then you put the row object in the table object. Fairly simple approach. You will create your header row, add it to the table, then you will get in a loop and create a new row for each iteration of the loop and add the textboxes to it. After you are done adding the stuff to the row, you can then add it to the table, and go to the next iteration.
Someone at my study group didn't know how to use the table control, so I put an example together. The example project is in the zip located here:
http://www.variantx.com/StudyGroupFi...03_Meeting.zip
-
Jan 15th, 2004, 02:54 PM
#5
Thread Starter
Junior Member
Thank for all your replies
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>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|