|
ok, ive got this now
public void CreateTextBoxes(Object sender, EventArgs e)
{
foreach (DataRow row in dataSetselectactivities.Tables[0].Rows)
{
TextBoxesHere.Controls.Add(new TextBox());
}
}
I am not showing the datatable in the code above because it would take up too much room but it does exist. Anyway Ive managed to create as many textboxes as there are rows dynamically. However now I need to fill each one with data from the datatable. How do I go about that?
thanks!
|
|
|
|
|
public void createTextBoxes(DataTable dt)
{
TextBox txt;
int Count = 1;
foreach (DataRow dr in dt.Rows)
{
txt = new TextBox();
txt.ID = "txt_" + Count;
txt.Text = dr["FieldName"].ToString();
Count+=1;
}
}
regard
kHan
please don't forget to vote on the post that helped you.
modified on Tuesday, July 8, 2008 8:05 AM
|
|
|
|
|
public void CreateTextBoxes(Object sender, EventArgs e)
{
TextBox tb;
foreach (DataRow row in dataSetselectactivities.Tables[0].Rows)
{
tb = new TextBox();
tb.Text = row["colName"].ToString();
TextBoxesHere.Controls.Add(tb);
}
}
|
|
|
|
|
thanks!!
OK final question how do I add a break after each textbox i.e
where abouts would I put it, I know the syntax shold be something like + " " but not sure which line to put it.
also how can I call the code on page_load, at the moment it is called through a button
thanks!
|
|
|
|
|
Cann't you use Repeater or DataGrid for this? That will be more simpler. Any way, you will have to create as many Literal Controls as there are textboxs and put it between textboxs to insert some text/html markup between them.
You can take out the code inside the button's click and put it in a method and call it from both the page_load and the button_click.
Nirandas,
a developer from India.
http://www.nirandas.com
|
|
|
|
|
ive tried putting <br> after the
tb.Text = row["fieldname"].ToString() + "<br />";
but this doesnt work.
<div class="ForumMod">modified on Tuesday, July 8, 2008 9:04 AM</div>
|
|
|
|
|
That would not work as your appending text to the textbox, and browser will not parse it while rendering. As I said, creating literal controls and adding them between textboxs is the way to go if you don't want to use repeater/Datagrid. Can you paste the code which you are using to add these textboxs to the page? Then I may be able to suggest the code to you.
|
|
|
|
|
foreach (DataRow row in dataSetselect.Tables[0].Rows)
{
lb = new Label();
tb = new TextBox();
lb.Text = row["field"].ToString();
tb.Text = row["field"].ToString();
TextBoxesHere.Controls.Add(lb);
TextBoxesHere.Controls.Add(tb);
}
thanks it would need to go somewhere in there
|
|
|
|
|
Change the line
lb.Text = row["field"].ToString();
to
lb.Text = "<br />" + row["field"].ToString();
This will add a line break before every label.
HTH
|
|
|
|
|
it throws up an error:
should it be like:
lb.Text = "
" + row["field"].ToString();
or
lb.Text = "" + row["field"].ToString();
|
|
|
|
|
The complete statement should be in a single line. And the quotes should not be empty, it should contain <br />
The line will be:
lb.Text = "<br />" + row["field"].ToString();
I didn't formatted the code correctly last time, sorry.
You can insert any html markup there, since you want a line break, use <br />
Goodluck.
|
|
|
|
|
No that doesn work either, all that does is put the <br /> in the actual textbox as text.
I need to add it afterwards but not sure of the syntax
Thanks anyway
|
|
|
|
|
Instead of label you can use a LiteralControl
LiteralControl lit=new LiteralControl();
lit.Text="<br />"
Textboxhere.controls.add(lit);
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
modified on Tuesday, July 8, 2008 11:04 AM
|
|
|
|
|
I am pasting the complete code:
foreach (DataRow row in dataSetselect.Tables[0].Rows)
{
lb = new Label();
tb = new TextBox();
lb.Text = "<br />" + row["field"].ToString();
tb.Text = row["field"].ToString();
TextBoxesHere.Controls.Add(lb);
TextBoxesHere.Controls.Add(tb);
}
Is it the same code as what you are using?
|
|
|
|
|
OK I got it now, I was putting the break in the textbox not the label!!
Thanks for your help in this
|
|
|
|
|
hi
i want to store static ip address to my database because if any one upload a video form their machine at any country i have to know this uploaded file uploaded by which ip and which country
so how to get static ip address
please help me
with regards,
bretto
|
|
|
|
|
Page.Request.UserHostAddress.ToString();
is this you was looking for ?
|
|
|
|
|
How we can Modify the Gridview Caption Style ?
|
|
|
|
|
see if this article helps:
http://www.velocityreviews.com/forums/t113102-gridview-caption-style.html
|
|
|
|
|
I have the following code. Now this code is working for every row apart from the last one in the gridview, why would this be?
thanks
for (int x = 0; x < GridView1.Rows.Count; x++)
{
GridViewRow row = GridView1.Rows[x];
string strID = GridView1.DataKeys[x].Values[0].ToString();
HyperLink hyp = ((HyperLink)row.FindControl("hl"));
hyp.Attributes["OnClick"] = "alert('You do not have the correct permissions to perform this action');return false;";
hyp.ForeColor = Color.Black;
}
|
|
|
|
|
Fixed it, needed to put this code in the ondatabound event rather then on row create event
cheers
|
|
|
|
|
You mean to say that you are looping through all the rows of the gridview inside rowdatabound event?
Apurva Kaushal
|
|
|
|
|
|
I don't know why are you using like that becauise onrowdatabound event gets executed for all the rows of the gridview and if inside that event again if you are looping through all the rows then it seems unnecessary and also will cause a performance issue.
Apurva Kaushal
|
|
|
|
|
Hi,
I am checking users on my page load. If my condition fails, I have to stop the page loading and I dont want to display any of my controls too. For this purpose, I dont want to redirect my page. What I have to do. What about response.End
If I use response.end, I am getting error msg as "cannot obtain value". What I have to do?. Pls help.
Balasubramanian K.
|
|
|
|