Control position in TableCell - c#

I am creaing a table cell, and in in, I want an image, and UNDER the image, a description. So, I attempted this:
TableCell cell = new TableCell();
ImageButton i = new ImageButton
{
ImageUrl = image.fullThumbPath,
PostBackUrl =
"~/fulldisplay.aspx?imageId=" + image.visibleId + #"&r=" +
GlobalVariables.RandomString(5)
};
cell.Controls.Add(i);
Label l = new Label
{
Text = image.description
};
l.Style.Add("font-weight", "bold");
cell.Controls.Add(l);
row.Cells.Add(cell);
However, what I end up with is the image, and NEXT to the image, a label. How would I ensure the label is under the image? I can't add a .

See if changing your code as below works for you.
Label l = new Label
{
Text = "<br>" + image.description
};
I have added a br tag before the image description so that the image description will come in next line.

Related

ASP.NET - Change label color and conc with string

I create a label and set his TEXT color to red. I use ForeColor property but with him not working :(
This is my UI:
This is my label code:
Label reqF = new Label();
reqF.Text = "*";
reqF.ForeColor = System.Drawing.Color.Red;
reqF.CssClass = "formvalidation";
reqF.Font.Size = 15; // 15px
This is my string code:
TableHeaderCell header1 = new TableHeaderCell();
header1.Text = "Destination" + reqF.Text; <----------- My label
tRow0.Cells.Add(header1);
In this line
header1.Text = "Destination" + reqF.Text;
you add only the text (*) to the destination, not the full div with the style on.
The easiest (and faster) way is to direct add the style online as:
header1.Text = "Destination <span style=\"color=red\">*</span>" ;
You are only using text of the control, not the whole control with styling. Your code should actually look something like that:
TableHeaderCell header1 = new TableHeaderCell();
LiteralControl literal = new LiteralControl();
literal.Text = "Destination";
header1.Controls.Add(literal);
header1.Controls.Add(reqF);
tRow0.Cells.Add(header1);
Note that here Literal control is used to insert the Description string, and then the whole Label with the * is being inserted.

How to set dynamically textbox required

I was created dynamically text boxes. So it must field by user.
So i want to add something like "RequiredFieldValidator". But I dont know how to add dynamically .User can't go to next step without filling these dynamically text boxes. So how can I control this?
this is my code
for (int i = count; i < no; i++)
{
Label lb = new Label();
lb.ID = "lbFname" + NumberOfControls;
lb.Text = "First Name :";
TextBox tbx = new TextBox();
tbx.ID = "Fname" + NumberOfControls;
AdultsListPlaceholder.Controls.Add(lb);
AdultsListPlaceholder.Controls.Add(tbx);
NumberOfControls++;
AdultsListPlaceholder.Controls.Add(new LiteralControl("<br />"));
AdultsListPlaceholder.Controls.Add(new LiteralControl("<br />"));
}
any idea?
Try something like this..
RequiredFieldValidator req = new RequiredFieldValidator();
req.ID = "Req" + NumberOfControls;;
req.ControlToValidate = "Fname" + NumberOfControls;;
req.ErrorMessage = "Name Required";
reqfldVal.SetFocusOnError = true;
AdultsListPlaceholder.Controls.Add(req);

Creating run time textbox in Windows Phone 7

I wanted to display no of course json objects in each textbox
but as they are unpredictable number of objects therefore i created textbox on the fly using this code
List<Course> Cdata = JsonConvert.DeserializeObject<List<Course>>(App.data);
TextBox[] Tblock = new TextBox[Cdata.Count];
double top = 0; int i = 0;
foreach (Course de in Cdata)
{
result += de.course_name + "\r\n";
result += "Total Absents = " + de.absents;
result += " + " + de.presents;
result += " = " + de.sessions + "\r\n\r\n\r\n";
Tblock[i] = new TextBox();
Tblock[i].Text = result;
Tblock[i].AcceptsReturn = true;
Tblock[i].TextWrapping = TextWrapping.Wrap;
Tblock[i].Width = 475;
Tblock[i].Height = 270;
Tblock[i].IsReadOnly = true;
Tblock[i].Margin =new Thickness (0,top,0,0);
Tblock[i].Visibility = System.Windows.Visibility.Visible;
Tblock[i].VerticalAlignment = System.Windows.VerticalAlignment.Top;
top += 270; i++;
result = "";
}
Now when i debug my app data it is working as its supposed to the only problem is textbox
never display on View
and i haven't coded any textbox in Xaml file of view
Thanks in Advance
You have to add the Textboxes to any existing Panel (generally to Grid or StackPanel) in the XAML as shown below
StackPanel sp = new StackPanel(); //Create stack panel before foreach loop
foreach (Course de in Cdata)
{
//your code which you shown above
sp.Children.Add(Tblock[i]); //Add all the Textboxes to the stackpanel
}
ContentPanel.Children.Add(sp); //And add the above stackpanel to the existing Grid named ContentPanel
By the way, I suggest you to use a ListBox with ItemTemplate to bind the data instead of creating the TextBoxes as shown above.
Also, I don't understand why you have choosen TextBox instead of TextBlock to display data

How to dynamically add an image to display in DataGridViewImageColumn?

I am working on WinForms, .NET2 project.
I am using a DataGridView control to display some data.
How can I dynamically add an image to display in a DataGridViewImageColumn ?
Have you tried setting the Image property?
Gets or sets the image displayed in the cells of this column when the
cell's Value property is not set and the cell's ValueIsIcon property
is set to false.
You can try following...
for (int i = 0; i < gridView.Columns.Count; i++)
{
TableCell tableCell = gridViewRow.Cells[i];
System.Web.UI.WebControls.Image img;
sortDirectionImageControl = new System.Web.UI.WebControls.Image();
string imageUrl = "~/Images/Myimage.jpg";
img.ImageUrl = imageUrl;
img.Style.Add(HtmlTextWriterStyle.MarginLeft, "10px");
tableCell.Wrap = false;
tableCell.Controls.Add(img);
}
Hope I get your question correctly.

Dynamically filling ListView with an image and a string

I would like to fill my ListView with do aligned elements, a little icon (either a confirm mark or a cross) and a string which contains the result of a question (Right / Wrong, that's why icon).
daInserire = new ListViewItem();
daInserire.Foreground = new SolidColorBrush(Colors.DarkGreen);
daInserire.Content = "Giusto: "+ straniero.Text + " = " + vocItaliano[current];
daInserire.HorizontalContentAlignment = HorizontalAlignment.Center;
daInserire.FontSize = 18;
//...
listViewConInfo.Items.Add(daInserire);
This works perfectly, I'd like to add before the string, on the same line an image.
Looks like you're using WPF, so you'll need to create a StackPanel for your Content property and add the Image and a Label to that StackPanel.
ListView lV = new listView();
ListViewItem Item = new ListViewItem();
WrapPanel wrap = new WrapPanel();
Image image = new image();
image.Source = <<yourSource>>;
Label label = new Label();
label.Content = "W/E you want";
wrap.Children.Add(image);
wrap.Children.Add(label);
Item.Content = wrap;
lV.Items.Add(Item);

Categories

Resources