Showing posts with label gtlt. Show all posts
Showing posts with label gtlt. Show all posts

Saturday, March 31, 2012

Table. Look Everywhere. Please help me out.

Hello,

I need to create a Table at runtime and I need the TBody tag to be:

<tbody id="itemContainer" runat="server"></tbody>

I need to to define its ID and making it run at server.

I tried everthing I could think of.

How can I do this?

Thanks,

Miguel

you can use a placeholder and do a placeholder.controls.add(pass the tablehere, table is your server object)


You didn't understand. I have no problems in working at runtime.

I create everything at runtime. The problem is that I can't find a property/way to define the ID of a Table's TBody tag when created at runtime.

Thanks,

Miguel


Hi Miguel,

Based on my understanding, you want to add the table in your asp.net application dynamically. If I have misunderstood you, please feel free to let me know.

The tbody is the html control. We can add the server table dynamically. For example,

Table t = new Table();
t.ID = "t";
TableHeaderRow hr = new TableHeaderRow();
hr.ID = "hr";
t.Controls.Add(hr);
TableCell tc = new TableCell();
tc.ID = "tc";
hr.Controls.Add(tc);
tc.Text = "test";

form1.Controls.Add(t);


I hope this helps.


publicvoid CreateEmployeeList()

{

System.Web.UI.WebControls.Table Tab =new System.Web.UI.WebControls.Table();

Tab.BorderWidth =newUnit(3);

Tab.BorderColor = System.Drawing.Color.AliceBlue;

Tab.CellPadding = 1;

//Tab.CellSpacing = 1;

TableRow Tr =newTableRow();

TableCell Tc1 =newTableCell();

TableCell Tc2 =newTableCell();

TableCell Tc3 =newTableCell();

TableCell Tc4 =newTableCell();

Label label4 =newLabel();

label4.ID ="label4";

label4.Text ="Employee ID";

Tc4.Controls.Add(label4);

Tr.Cells.Add(Tc4);

Label label1 =newLabel();

label1.ID ="label1";

label1.Text ="Employee";

Tc1.Controls.Add(label1);

Tr.Cells.Add(Tc1);

Label label2 =newLabel();

label2.ID ="label2";

label2.Text ="Attendance";

Tc2.Controls.Add(label2);

Tr.Cells.Add(Tc2);

Label label3 =newLabel();

label3.ID ="label3";

label3.Text ="Remark";

Tc3.Controls.Add(label3);

Tr.Cells.Add(Tc3);

Tab.Rows.Add(Tr);

Tr.BackColor = System.Drawing.Color.AliceBlue;

EmployeeList =EmployeeReg.SelectStaff();

EmployeeReg empreg;

EmployeeNo = EmployeeList.Count;

Empid =newLabel[EmployeeList.Count];

Empname =newLabel[EmployeeList.Count];

Attendance =newRadioButtonList[EmployeeList.Count];

Remark =newTextBox[EmployeeList.Count];

for (int i = 0; i < EmployeeList.Count; i++)

{

empreg =newEmployeeReg();

empreg = EmployeeList[i];

//initialize table row

Tr =newTableRow();

//initialize columns in particular row

Tc1 =newTableCell();

Tc2 =newTableCell();

Tc3 =newTableCell();

Tc4 =newTableCell();

//Generating Employee ID in table.

Label Lbl2 =newLabel();

Lbl2.ID ="lblEmpid" + i.ToString();

Lbl2.BackColor= System.Drawing.Color.AliceBlue;

Lbl2.Text = empreg.EmployeeID.ToString();

Empid[i] = Lbl2;

Tc4.Controls.Add(Lbl2);

Tr.Cells.Add(Tc4);

//Generating Employee name in table.

Label Lbl1 =newLabel();

Lbl1.ID ="lblName" + i.ToString();

Lbl1.Text = empreg.EmployeeName.ToString();

Empname[i] = Lbl1;

Tc1.Controls.Add(Lbl1);

Tr.Cells.Add(Tc1);

//Genertaing radiobuttonlist for attendance

RadioButtonList rdbl =newRadioButtonList();

rdbl.ID ="rdblAtt" + i.ToString();

rdbl.RepeatDirection =RepeatDirection.Horizontal;

ListItem item1 =newListItem();

//item1.Text = "Present";

item1.Value ="P";

item1.Selected =true;

rdbl.Items.Add(item1);

ListItem item2 =newListItem();

// item2.Text = "Absent";

item2.Value ="A";

rdbl.Items.Add(item2);

ListItem item3 =newListItem();

// item3.Text = "Off Day";

item3.Value ="O";

rdbl.Items.Add(item3);

ListItem item4 =newListItem();

// item4.Text = "Half Day";

item4.Value ="H";

rdbl.Items.Add(item4);

Attendance[i] = rdbl;

Tc2.Controls.Add(rdbl);

Tr.Cells.Add(Tc2);

//Genertaing TextBox for Remark

TextBox Txt1 =newTextBox();

// Txt1.ID = "txtRemark" + i.ToString();

Remark[i] = Txt1;

Remark[i].ID ="txtRemark" + i.ToString();

Remark[i].Text ="";

Tc3.Controls.Add(Txt1);

Tr.Cells.Add(Tc3);

Tab.Rows.Add(Tr);

}

this.Panel1.Controls.Add(Tab);

}

Thursday, March 22, 2012

taking text from a drop down list and want to insert into a database


<%@dotnet.itags.org. Page Language="VB" Debug="true" %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.OleDb" %>
<script runat="server"
dim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\admin\Desktop\Reminder\dbReminder.mdb")

Sub btnSet_Click(obj as Object, e as EventArgs)

dim objTrans as OleDbTransaction
dim objCmd as OleDbcommand = new OleDbcommand ("INSERT INTO tblReminder (mobile, station, reminder, time) VALUES (@dotnet.itags.org.MOBILE, @dotnet.itags.org.STATION, @dotnet.itags.org.REMINDER, @dotnet.itags.org.TIME)", Conn)
dim objParam as OleDbParameter

objParam = objCmd.Parameters.Add("@dotnet.itags.org.MOBILE", oleDbType.char)
objParam.Direction = ParameterDirection.Input
objParam.Value = lblUser.Text

objParam = objCmd.Parameters.Add("@dotnet.itags.org.STATION", oleDbType.char)
objParam.Direction = ParameterDirection.Input
objParam.Value = lblStation.Text

objParam = objCmd.Parameters.Add("@dotnet.itags.org.REMINDER", oleDbType.Char)
objParam.Direction = ParameterDirection.Input
objParam.Value = DDLFields.SelectedItem.Text

objParam = objCmd.Parameters.Add("@dotnet.itags.org.TIME", oleDbType.char)
objParam.Direction = ParameterDirection.Input
objParam.Value = tbTime.Text

Conn.Open()

objTrans = Conn.BeginTransaction()
objCmd.Transaction = objTrans

try
objCmd.executeNonQuery
objTrans.commit()
catch ex as OleDbException
objTrans.RollBack()
lblError.Text = "Error inserting reminder into database"
end try

objcmd.Connection.Close()
End sub

Private Sub Page_Load(sender As Object, e As System.EventArgs)
If Not Page.IsPostBack Then

dim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\admin\Desktop\Reminder\dbReminder.mdb")
dim objTrans as OleDbTransaction
dim objCmd as OleDbcommand = New OleDbCommand("SELECT time + ' ' + programme as fieldone FROM tblRTE ", Conn)
Conn.Open()

DDLFields.DataSource = objCmd.ExecuteReader()

DDLFields.DataTextField = "fieldone"
DDLFields.DataValueField = "fieldone"
DDLFields.DataBind()

Conn.Close()
End If

If Not Request.Cookies("rm_user") Is Nothing Then
lblUser.Text = Request.Cookies("rm_user").Value
end if
End Sub

</script>

This is the code im using to take the information from the form and enter it into the database.
But it displays my error message every time...
Is it correct?
The part im not sure about is this:

objParam = objCmd.Parameters.Add("@dotnet.itags.org.REMINDER", oleDbType.Char)
objParam.Direction = ParameterDirection.Input
objParam.Value = DDLFields.SelectedItem.Text

Is this the correct way of taking the selected items text from the ddl?

Thanks.Your code looks good, however your SQL looks dodgy. Thisthread in the DevShed forum should help.
I do somthing similar on a page. I think your problem is that the code for the DDL is in the on postback block. When the page is posted back ( user chose something and clicked button to do save) the ddl is not populated.
Try taking the DDL code out of the is postback IF block...


Private Sub Page_Load(sender As Object, e As System.EventArgs)

If Not Page.IsPostBack Then
End If

dim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\admin\Desktop\Reminder\dbReminder.mdb")

dim objTrans as OleDbTransaction

dim objCmd as OleDbcommand = New OleDbCommand("SELECT time + ' ' + programme as fieldone FROM tblRTE ", Conn)

Conn.Open()

DDLFields.DataSource = objCmd.ExecuteReader()

DDLFields.DataTextField = "fieldone"

DDLFields.DataValueField = "fieldone"

DDLFields.DataBind()

Conn.Close()

If Not Request.Cookies("rm_user") Is Nothing Then

lblUser.Text = Request.Cookies("rm_user").Value

end if

End Sub

also, I don't think you need the transaction stuff. Transactions are used for multiple DB actions. not a single action. The try block should suffice. If the single DB action fails ( your insert) there are no other actions to rollback.
Hope that helps
> I think your problem is that the code for the DDL is in the on postback block. When the
> page is posted back ( user chose something and clicked button to do save) the ddl is not
> populated. Try taking the DDL code out of the is postback IF block...

This is not the problem. The DDL is repopulated via ViewState on PostBack.

I do agree about the Transaction.

One thing that would help solve this is for emmettd to post the error message.
I talking about the error message in my code.

its "Error inserting reminder into database"

its in the code, in the btnSet_click, near the end.
change this line and let us know what you get

lblError.Text =ex.tostring()