TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hiregoud Bidagar
NA
96
1.4k
dynamic textbox creation on buttn and getting its value back
Jul 4 2015 8:06 AM
on btnGetSubjects_Clik Event The Following Code Runs
Retrieve GSubj = new Retrieve();
DataSet DS = new DataSet();
DS = GSubj.GetSubjects(SclID, ClassID);
if (DS != null)
{
if (DS.Tables[0].Rows.Count > 0)
{
Table CreatTable = new Table();
CreatTable.ID = "tblDynamic";
//DS.Tables[0].Rows[rowNum][columnName].ToString();
for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
{
TableRow row;
row = new TableRow();
row.Width = 250;
TableCell cell1 = new TableCell();
cell1.Width = 130;
Lbl = new Label();
Lbl.ID = DS.Tables[0].Rows[i][0].ToString();
Lbl.Text = DS.Tables[0].Rows[i][1].ToString();
cell1.Controls.Add(Lbl); // Creating Labels With Subject ID as Label ID and Subject Name as Label Text
row.Cells.Add(cell1);
TableCell cell2 = new TableCell();
txtbox = new TextBox();
txtbox.ID = "Sub" + DS.Tables[0].Rows[i][0].ToString();
txtbox.Attributes.Add("runat", "Server");
cell2.Controls.Add(txtbox); // Creating Textbox With Subject ID as Textbox ID
row.Cells.Add(cell2);
CreatTable.Rows.Add(row);
}
TablePlaceHolder.Controls.Add(CreatTable);
}
}
After Creating I am Trying to get the filled values
protected void btnSubmit_Click(object sender, EventArgs e)
{
Hashtable Subjects = new Hashtable();
foreach (Control ctrl in TablePlaceHolder.Controls)
{
if (ctrl is TextBox)
{
Subjects.Add(((TextBox)ctrl).ID, ((TextBox)ctrl).Text); // Filling Subject Code and marks to the Hash Table
}
}
}
but the place holder is null and its not showing any values
Code in aspx Page
<asp:PlaceHolder ID="TablePlaceHolder" runat="server" />
<br />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click" />
please suggest me
Advance Thank you...
Reply
Answers (
1
)
Using Data Annotations for Model Validation
image desplay in gridview