Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I've loaded picture names into a data table on aspx, but is this the best way to put them on the page....
private void LoadPics()
{
Image1.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[0]["name"].ToString();
Label1.Text = MyClass.dtprop.Rows[0]["name"].ToString();
Image2.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[1]["name"].ToString();
Label2.Text = MyClass.dtprop.Rows[1]["name"].ToString();
Image3.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[2]["name"].ToString();
Label3.Text = MyClass.dtprop.Rows[2]["name"].ToString();
Image4.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[3]["name"].ToString();
Label4.Text = MyClass.dtprop.Rows[3]["name"].ToString();
Image5.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[4]["name"].ToString();
Label5.Text = MyClass.dtprop.Rows[4]["name"].ToString();
Image6.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[5]["name"].ToString();
Label6.Text = MyClass.dtprop.Rows[5]["name"].ToString();
}
you can try with this code, based on OfType operator linq
var controls = this.Controls.OfType<Image>();
foreach(var item in controls)
{
....
}
if you wish add them to page, you can use PlaceHolder control
Ph.Contols.Add(yourImage);
you set your PlaceHolder in the target page
<asp:PlaceHolder id ="Ph" runat="server"/>
link :http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.placeholder%28v=vs.80%29.aspx
link : http://msdn.microsoft.com/fr-fr/library/vstudio/bb360913.aspx
Another solution : you can also use GridView control, bind this control on your DataTable and define template field
...
<asp:TemplateField>
<ItemTemplate>
<asp:Image id="img" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
...
Related
<asp:TemplateField HeaderText="DOB" >
<ItemTemplate>
<telerik:RadDatePicker RenderMode="Lightweight" ID="txtDob" runat="server"
DateInput-DateFormat="yyyy-MM-dd"
DateInput-DisplayDateFormat="dd MMM yyyy"
ClientEvents-OnDateSelected="OnDateSelected"></telerik:RadDatePicker>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Age" >
<ItemTemplate>
<asp:Label ID="lblAge" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<script type="text/javascript">
function OnDateSelected(sender, e) {
if (e.get_newDate() != null) {
var dob = e.get_newDate(),
today = new Date(),
ageInMilliseconds = new Date(today - dob),
years = ageInMilliseconds / (24 * 60 * 60 * 1000 * 365.25),
age = parseInt(years);
//how to access the lable control
//$("span[id$='lblAge']").text(age);
}
}
can not access the lblAge control in the OnDateSelected event of telerik:RadDatePicker. if somehow rowIndex is passed then can set by td
var td = $("table[id$='" + gridViewCtlId + "'] tr:eq(" + rowIndex + ") td:first");
Here is an example code that could be a viable solution for your scenario:
<script type="text/javascript">
function OnDateSelected(sender, e) {
if (e.get_newDate() != null) {
var dob = e.get_newDate(),
today = new Date(),
ageInMilliseconds = new Date(today - dob),
years = ageInMilliseconds / (24 * 60 * 60 * 1000 * 365.25),
age = parseInt(years);
//how to access the lable control
//$("span[id$='lblAge']").text(age);
// get reference to the HTML element of RadDatePicker
var datePickerElement = sender.get_element();
// get reference to the current Grid row using the jQuery closest() method and search for the tr element.
var currentGridRow = $(datePickerElement).closest('tr');
// search for the label which ID contains "lblAge"
var lblAge = currentGridRow.find('span[id*="lblAge"]');
// exit the logic if the label is not found
if (!lblAge) return;
// set the Label's text
lblAge.text(age);
}
}
</script>
Here is a short video that shows how the solution for this scenario was achieved. Also, it could prove a good way for debugging an application on client-side using the Developer Tools of the browser: OnDateSelected set Label's Text in the same row
Here are some references that you may review for more information on the methods used to achieve this scenario:
.closest()
.find()
Attribute Contains Selector [name*=”value”]
I would also advise checking out the RadDatePicker client-side programming article describing the usage of the RadDatePicker control's APIs.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a c# FlowLayoutPanel container to which I am adding a number of labels with Label.Text set to different values ie Label.Text = "ABCDEF".
What is the best way to search all the labels in the container to find the
a particular label with the Text = "ABCDEF"?
Thank You
You can find the label with text as follow:
foreach (var item in flowLayoutPanel1.Controls)
{
if (item is Label)
{
if ("ASDF" == ((Label)item).Text)
{
MessageBox.Show("found it");
}
}
}
Also if you know your component's name, you can search it as below:
foreach (var item in flowLayoutPanel1.Controls.Find("label1", true))
{
if ("ASDF" == ((Label) item).Text)
{
MessageBox.Show("found it");
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So I found this blog post
http://lostechies.com/gabrielschenker/2009/01/23/synchronizing-calls-to-the-ui-in-a-multi-threaded-application/
And I've spent the morning trying to learn from it.
It updates a single label with the "stock quote".
MessageBus.Register<QuoteMessage>(m => label1.Text = m.Symbol+":"+m.Quote.ToString("n2"));
I would like to update more than one label with just one message handler. Specifically I might want to change a different label depending on what is in the QuoteMessage object. Given the code below, I can only update the labels with a handler per label.
Doing
MessageBus.Register<QuoteMessage>(m => label1.Text = m.Symbol+":"+m.Quote.ToString("n2"));
MessageBus.Register<QuoteMessage>(m => label2.Text = m.Symbol + ":" + m.Quote.ToString("n2"));
MessageBus.Register<QuoteMessage>(m => label3.Text = m.Symbol + ":" + m.Quote.ToString("n2"));
MessageBus.Register<QuoteMessage>(m => label4.Text = m.Symbol + ":" + m.Quote.ToString("n2"));
just gets me 4 labels displaying the same thing.
I think what you are missing is that the handler can have logic in the delegate action. I would do something like this:
MessageBus.Register<QuoteMessage>(m => {
if (m.Symbol == "MSFT") {
label1.Text = m.Symbol+":"+m.Quote.ToString("n2");
label2.Text = m.Symbol+":"+m.Quote.ToString("n2");
}
else if (something) {
// Do something else
label3.Text = m.Symbol+":"+m.Quote.ToString("n2");
}
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is for my button named Edit, when you have an entry into the shopping basket and click on the entry and click Edit it opens up a new window which allows you to edit the entries, product name, quantity or price. This is what I have and it compiles and runs fine but is there an easier way to write it?
private void btn_Edit_Click(object sender, EventArgs e)
{
if (lst_Results.SelectedIndex >= 0)
{
// Want to edit the value of the Item
Edit editbutton = new Edit();
editbutton.NameOfItem =
basket.Items[lst_Results.SelectedIndex].ItemName;
editbutton.Quantity = basket.Items[lst_Results.SelectedIndex].Quantity;
editbutton.ReplacementValue =
basket.Items[lst_Results.SelectedIndex].Price;
if (editbutton.ShowDialog() == DialogResult.OK)
{
basket.UpdateReplacementValue(basket.Items[lst_Results.SelectedIndex].ItemName, editbutton.Quantity, editbutton.ReplacementValue);
RenderLibrary();
}
}
}
At least, you can write out the repeating array access.
// Want to edit the value of the Item
Edit editbutton = new Edit();
var item = basket.Items[lst_Results.SelectedIndex];
editbutton.NameOfItem = item.ItemName;
editbutton.Quantity = item.Quantity;
editbutton.ReplacementValue = item.Price;
if (editbutton.ShowDialog() == DialogResult.OK)
{
basket.UpdateReplacementValue(item.ItemName, editbutton.Quantity, editbutton.ReplacementValue);
RenderLibrary();
}
Also, you might want to just pass the object as parameter to the control, and edit it there using data binding.
I created a range validator and would like to trigger it once the submit button was clicked.
RangeValidator rv_tbAbsenceDay = new RangeValidator();
rv_tbAbsenceDay.ID = "rv_tbAbsenceDay" + tbAbsenceDay.ID;
rv_tbAbsenceDay.ControlToValidate = tbAbsenceDay.ID;
rv_tbAbsenceDay.EnableClientScript = true;
rv_tbAbsenceDay.Display = ValidatorDisplay.Dynamic;
rv_tbAbsenceDay.MinimumValue = DateTime.Now.AddMonths(-6).ToString("d");
rv_tbAbsenceDay.MaximumValue = DateTime.Now.ToString("d");
rv_tbAbsenceDay.ErrorMessage = "Date cannot be older than 6 months and not in the future.";
rv_tbAbsenceDay.SetFocusOnError = true;
plcMyStaff.Controls.Add(rv_tbAbsenceDay);
plcMyStaff is a placeholder.
<asp:PlaceHolder ID="plcMyStaff" runat="server"></asp:PlaceHolder>
How do I get hold of the created range validator to trigger it i.e. rv.validate(); ?
I have tried this:
protected void MarkAsSick_Command(Object sender, CommandEventArgs e)
{
DropDownList tempddlReason = (DropDownList)plcMyStaff.FindControl("ddlReason" + e.CommandArgument.ToString());
TextBox temptbAbsenceDay = (TextBox)plcMyStaff.FindControl("tbAbsenceDay" + e.CommandArgument.ToString());
TextBox temptbLastDayWorked = (TextBox)plcMyStaff.FindControl("tbLastDayWorked" + e.CommandArgument.ToString());
RangeValidator temprv_tbAbsenceDay = (RangeValidator)plcMyStaff.FindControl("rv_tbAbsenceDay" + e.CommandArgument.ToString());
temprv_tbAbsenceDay.validate();
...
Hope you can help me.
thanks,
Andy
First off to debug this I would suggest examining the plcMyStaff object in which you are adding the control to see if it does in fact contain the control you wish to access.
You should be able to retrieve it from the Page object that your webform inherits.
Page.FindControl();
// Or you can Iterate through each control to see what the control is called and test for the name you want
foreach (var control in Page.Controls)
{
}