Hello I have a DataList that has four lables and they all end with a number 1-4. In my code behind I have a for loop and an array that I want to set the labels of the Datalist with.
for (int x = 0; x< cartreciept.Items.Count; x++)
{
DataListItem item = cartreceipt.Items[x];
string catalogtype = ("select CatalogType From SC Where OrNum=" + OrNum)
if (catalogtype="TC")
{
((Panel)item.FindControl("pnlIprintInfo")).Visible = true;
string scRID = ("Select SCRID From SC Where OrNum =" + OrNum
for(int y = 1; y<5; y++)
{
string lT[y] = (Select LineText From table Where SCartRD =" + scRID + " AND LN=" + y)
((Label)item.FindControl("lbl[y]")).text = lT[y];
}
}
}
So would the ((Label)item.FindControl("lbl[y]")) work? most of this code is just pseudo code until I figure the details out. If you need to know anything else I can provide what needs to be known, I am open to other suggestions as well. Thank you to any one who can offer some help.
You can use this code - based on string.Format("....{0}",arguments)
var control = (Label)item.FindControl(string.Format("lbl{0}",y));
I suggest you to use DataList.ItemDataBound
Link : http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx
Related
I am trying to get a clickable file path using asp.net c# visual studios web form, meaning to say that it is like windows file explorer, allowing the person to navigate through the different levels of folders etc, can anyone provide any links to help get me started? [1]: https://i.stack.imgur.com/WyyLq.png
You could try to get the path string and divide it in multiple pieces. Then store them in multiple textboxes, labels, buttons or whatever you want. My form looks like this: Picture Form
Secondly, you will have to update those (in my case) textboxes to save the path. See my code and decide what you want to use, and if you have to modify it.
private void changePath()
{
String path = webBrowser1.Url.AbsolutePath;
if (path.Contains(#"/")) { path = path.Replace(#"/", #"\"); }
string[] directories = path.Split(Path.DirectorySeparatorChar);
int count = directories.Count();
if (count <= 6)
{
textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = "";
for (int i = 0; i < count; i++)
{
String txt = "textBox" + (i + 1);
TextBox tbx = this.Controls.Find(txt, true).FirstOrDefault() as TextBox;
tbx.Text = directories[i];
}
}
else
{
int p = count / 6;
int z = count - (p * 6);
for (int i = 0; i < count; i++)
{
int g = i - 1;
String txt = "textBox" + (i + 1);
TextBox tbx = this.Controls.Find(txt, true).FirstOrDefault() as TextBox;
tbx.Text = directories[z];
z++;
if (i == 5)
{
break;
}
}
}
}
Second step is to make click functions on the (in my case) textboxes. Here is one sample of how you can do this. See for yourself what you can do.
private void textBox5_Click(object sender, EventArgs e)
{
if(!textBox5.Text.Equals(String.Empty))
{
String p = webBrowser1.Url.AbsolutePath;
if(!textBox6.Text.Equals(String.Empty))
{
webBrowser1.Url = new Uri(p.Replace(#"/" + textBox6.Text, ""));
}
}
}
This code will remove the last piece, leaving you with a new path. Example:
Before: C:\Users\USERNAME\Desktop\C#
After:
After: C:\Users\USERNAME\Desktop
Again, you have to look what works for you. There are multiple ways to resolve your issue.
Good Luck!
Twan.
I'm making an application and i need get the same interval of space from a line in many items (strings). My code is something like that
p = "";
int contaletras = 0;
int maxPalavra = 14; int xpto;
contaletras = item.Length;
xpto = maxPalavra - contaletras;
for (int i = 0; i < xpto; i++)
{
p = p + " ";
}
StringBuilder m = new StringBuilder();
m.Append(item);
m.Insert(item.Length, p);
RTB_Exames.Text = RTB_Exames.Text + m.ToString() + " ";
So, my item.length is all the time 14 characteres. But
i dont know why i have this result when in textvisualizer in c# i have this. I will show some image in this link:
https://drive.google.com/file/d/0B5tH_Qo3-GvhSEJrOXVsTzhIQVk/edit?usp=sharing
https://drive.google.com/file/d/0B5tH_Qo3-GvhaTN5WUM1M2M3QVU/edit?usp=sharing
You can either set the font in the visual editor for the TextBox control or set it via:
RTB_Exames.FontFamily = new FontFamily("Consolas");
I want to automatically add parameters based on the input of control numbers.
the following code will give me sp_INSERT #COL5, sp_INSERT #COL4, so on...
control = 5;
while(1<=control)
column = '#COL'
string setValues = "sp_INSERT'" + column + control + "';"
control = control - 1;
What I want to achieve is sp_INSERT #COL5, #COL4, #COL3, so on...
Just... loop?
int control = 5;
string colPrefix = "#COL";
var sql = new StringBuilder("sp_INSERT ").Append(colPrefix).Append(control);
// note first item has different format due to comma
for(int i = control - 1; i > 0; i--)
{
sql.Append(", ").Append(colPrefix).Append(i);
}
sql.Append(';');
string s = sql.ToString();
Simple loop, not a complete solution, but it might help...
string myString = "INSERT ";
for (int i = 5; i > 0; i--)
myString = string.Format("{0} #COL{1}, ", myString, i);
I am trying To create check boxes list dynamically using c# and insert the check box text values to databse.But I dnt Understand How Can I Create and access its values to insert into db.Is there any one help me in this regard coz i have no strong idea except this.
public void CreateCheckBox(int n)
{
for (int i = 0; i <= n; i++)
{
Response.Write(#"<input type=""checkbox"" name=""link"" value=" + "CA0" + i +">"+"CA0"+ i +"<br>") ;
}
}
How Can I access its value to be inserted to db.Plz Help
you can assign an id attribute to the checkboxes like:
for (int i = 0; i <= n; i++)
{
Response.Write(#"<input id='check'" + i.ToString() + " type=""checkbox"" name=""link"" value=" + "CA0" + i +">"+"CA0"+ i +"<br>") ;
}
then on the event that you want to retrieve the values simply you can use the following:
for(int i=0;i<=n;i++)
{
var data=Request.Form["check" + i.ToString()]; // this should hold the value of the checkbox as string
}
hope that it will help
regards
I'm using LINQ and returning a list to my Business Logic Layer. I'mtrying to change one of the values in the list (changing the 'star' rating to an image with the number of stars).
Although the counter (i) appears to be working, the FOR loop is not working correctly. The first time through it stops at the correct IF but then it pops out at the ELSE statement for everything and all values end up with "star0.png." It appears as though I'm not cycling through the list??? Thanks in advance!
for (int i = 0; i < ReviewList.Count; i++)
{
string serviceCode = ReviewList[i].SERVICE.SERVICE_DESC;
if (serviceCode == "*")
{
ReviewList[i].SERVICE.SERVICE_DESC = "star1.png";
}
else if (serviceCode == "**")
{
ReviewList[i].SERVICE.SERVICE_DESC = "star2.png";
}
else if (serviceCode == "***")
{
ReviewList[i].SERVICE.SERVICE_DESC = "star3.png";
}
else if (serviceCode == "****")
{
ReviewList[i].SERVICE.SERVICE_DESC = "star4.png";
}
else
{
ReviewList[i].SERVICE.SERVICE_DESC = "star0.png";
}
}
If all values end up at star0.png, then you are cycling through the list. The fact that the else statement is the only code being executed for each element suggests a logical error -- did you perhaps mean to do something like this?
string serviceCode = ReviewList[i].SERVICE.SERVICE_CODE;
I dont think its an issue of the for loop working properly... your syntax is good and as written will iterate ReviewList.Count # of times.
I would step through and verify the contents of ReviewList first.
Let me know what you find
If you know each item will consist of a number of stars, why not do this?:
for (int i = 0; i < ReviewList.Count; i++)
{
string serviceCode = ReviewList[i].SERVICE.SERVICE_DESC;
ReviewList[i].SERVICE.SERVICE_DESC = "star" + serviceCode.Length + ".png";
}
Protection on double pass and with else condition
for (int i = 0; i < ReviewList.Count; i++)
{
string serviceCode = ReviewList[i].SERVICE.SERVICE_DESC;
if(!serviceCode.Contains(".png")) { // once name set should not be modified
if(serviceCode.Contains("*"))
ReviewList[i].SERVICE.SERVICE_DESC = "star" + serviceCode.Length + ".png";
else
ReviewList[i].SERVICE.SERVICE_DESC = "star0.png";
}
}
alternate LINQ approach
ReviewList.ForEach(rs=>if(!rs.SERVICE.SERVICE_DESC.Contains(".png"))
{ rs.SERVICE.SERVICE_DESC =
"star" + rs.SERVICE.SERVICE_DESC.Length + ".png"});