I have to set a list box which shows data from database column . Each time different length of data will come to list-box. so according to this I have to change its height fit to content . How is it ?
<asp:ListBox ID="ListBox1" runat="server" BackColor="White" Height="14000px"
Width="1312px"></asp:ListBox>
while (dr.Read())
{
string poem = dr[0].ToString();
byte[] newFileData = Encoding.ASCII.GetBytes(poem);
string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
string[] poem_details = fileString.Split(new string[] { " ", "\n" }, StringSplitOptions.None);
foreach (var line in score_details)
{
ListBox1.Items.Add(line);
}
}
Try this-
Listbox.rows = Listbox.Items.count
OR
you can also set size attribute as follows-
$(document).ready(function() {
$('#<%=this.ListBox1.ClientID%>').attr('size', $('#<%=this.ListBox1.ClientID%> option').length);
});
Related
I have a gridview ,gridview data is from database.I have a last column which is asp:FileUpload for user to insert new attachment if they want to,thing i wanted to do here is ,my backend c# will check if row asp file upload is not empty,then will upload new revision to that form.if empty,dont upload new revision to that form.
<asp:TemplateField HeaderText="Upload New Form" HeaderStyle-BackColor="DarkBlue" HeaderStyle-Font-Bold="false" HeaderStyle-ForeColor="White" ItemStyle-Width="5%">
<ItemTemplate>
<asp:FileUpload ID="newdoc" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
this is the column i created for user to insert new file if they want.
protected void Button11_Click(object sender, EventArgs e)
{
//System.Diagnostics.Debugger.Launch();
string data = "";
foreach (GridViewRow row in GridView3.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
FileUpload chkRow = (row.Cells[7].FindControl("newdoc") as FileUpload);
if (FileUploadControl.HasFile)
{
string id = row.Cells[2].Text + '-'+row.Cells[3].Text;
data = data + id + ",";
}
}
}
string[] alldata = data.Split(',');
foreach (string dataid in alldata )
{
if (dataid.Equals(""))
continue;
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + dataid + "');", true);
}
}
my c# logic is like this,i will check each row,if the uploadcontrol is not empty then dont add the id into data list,after collect all the row that needed to update new revision i will split the list update it 1 by 1,i try to alert out the id but value i get is empty.any ideas where i did wrong??
i suspeect something wrong in this line " string id = row.Cells[2].Text + '-' + row.Cells[3].Text;"
use BoundField instead of TemplateField..
string test = row.Cells[2].Text;
I have a asp:repeater control on my .aspx and in the code behind I am binding its datasource to a Collection of type KeyValuePair[]<Literal,String>. I was choosing literal so that I could surround selected words in literal text with <strong> or <b> html tag. Well I succeeded in doing it but I am not finding a way to display the literal text in the asp:hyperlink's Text part of asp:repeater
My .aspx code is as follow:
<asp:Repeater ID="repLinks" runat="server">
<ItemTemplate>
<div onclick="window.open('<%# ((KeyValuePair<Literal,string>)Container.DataItem).Value %>','_blank');">
<div>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="<%# ((KeyValuePair<Literal,string>)Container.DataItem).Value %>" Text="<%#((KeyValuePair<Literal,string>)Container.DataItem).Key.Text %>"
Font-Size='Large' ForeColor='Blue' Font-Names="Open Sans" CssClass="linkstyle" />
<br />
</div>
</div>
</ItemTemplate>
</asp:Repeater>
I need help on how to display the .Key.Text part in asp:Hyperlink.
I added the keyValuePair as follow:
char[] seperator = { ' ' };
String[] explodedString = Results1[index].Key.Split(seperator);
List<String> Query= new List<string>(TextBox1.Text.Trim().ToLowerInvariant().Split(seperator,StringSplitOptions.RemoveEmptyEntries));
for (int i = 0; i < explodedString.Length; i++)
{
if (Query.Contains(explodedString[i].ToLowerInvariant()) == true)
{
explodedString[i] = "<strong>" + explodedString[i] + "<strong>";
}
}
Literal temp = new Literal();
temp.Text = explodedString.ToString();
TryCurrentWindow[index] = new KeyValuePair<Literal, string>(temp, Results1[index].Value);
Here TryCurrentWindow is the KeyValuePair[] and explodedstring[] is the text string splitted by '' char which I want to modify and Query[] is list of my keyWords
Problem:
You are not closing <strong> tag like this </strong>.
You are simply doing ToString() to string[] array.
Updated this line:
explodedString[i] = "<strong>" + explodedString[i] + "</strong>";
Also change below code:
Literal temp = new Literal();
temp.Text = explodedString.ToString();
With this:
Literal temp = new Literal();
temp.Text = string.Join(" ", explodedString);
As indexes are modified in the string[] array. You are required to join array to get modified string[] array.
Updated Code Snippet:
char[] seperator = { ' ' };
String[] explodedString = Results1[index].Key.Split(seperator);
List<String> Query= new List<string>(TextBox1.Text.Trim().ToLowerInvariant().Split(seperator,StringSplitOptions.RemoveEmptyEntries));
for (int i = 0; i < explodedString.Length; i++)
{
if (Query.Contains(explodedString[i].ToLowerInvariant()) == true)
{
explodedString[i] = "<strong>" + explodedString[i] + "</strong>"; //changed
}
}
Literal temp = new Literal();
temp.Text = string.Join(" ", explodedString); //changed
TryCurrentWindow[index] = new KeyValuePair<Literal, string>(temp, Results1[index].Value);
when i click to button it'll take these links from c:\text.txt file and it will write into my richtextbox
in my text.txt:
en.wikipedia.org/wiki/Extreme_programming
en.wikipedia.org/wiki/Boolean_algebra
en.wikipedia.org/wiki/Microsoft_Visual_Studio
en.wikipedia.org/wiki/Web_crawler
(there is no empty rows between links)
after that i want to call that links line by line into my other button to parse its html codes and write to other richtextbox
here is my parse button code:
private void button2_Click(object sender, EventArgs e)
{
string s = KaynakKodunuCek("http://tr.wikipedia.org/wiki/Lale");
// <p ... > </p> tagları arasını alıyor.(taglar dahil)
Regex regex = new Regex("<p[^>]*>.*?</p>");
string gelen = s;
string inside = null;
Match match = regex.Match(gelen);
if (match.Success)
{
inside = match.Value;
richTextBox3.Text = inside;
}
string outputStr = "";
foreach (Match ItemMatch in regex.Matches(gelen))
{
Console.WriteLine(ItemMatch);
inside = ItemMatch.Value;
//boşluk bırakıp alt satıra yazıyor
outputStr += inside + "\r\n";
}
richTextBox3.Text = outputStr;
}
here i want to call links string s = KaynakKodunuCek("here");
Or should i use listbox instead of richtextbox
Yes, listBox would be better.But if you want to do it with richTexBox you can use this:
string[] links = richTextBox2.Text.Split(new [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
for(int i=0;i<links.Length;i++)
{
string s = KaynakKodunuCek(links[i]);
...
}
I have a DecXpress report and the datasource shows a filed where the data is comming something like
PRODUCT - APPLE<BR/>ITEM NUMBER - 23454</BR>LOT NUMBER 3343 <BR/>
Now that is how it is showing in a cell, so i decided to decoded, but nothing is working, i tried HttpUtility.HtmlDecode and here i am trying WebUtility.HtmlDecode.
private void xrTableCell9_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
XRTableCell cell = sender as XRTableCell;
string _description = WebUtility.HtmlDecode(Convert.ToString(GetCurrentColumnValue("Description")));
cell.Text = _description;
}
How can I decode the value of this column in the datasource?.
Thank you
If you need to show the description with the < /> also, you need to use HtmlEncode.
If you need to extract the text from that html
public static string ExtractTextFromHtml(this string text)
{
if (String.IsNullOrEmpty(text))
return text;
var sb = new StringBuilder();
var doc = new HtmlDocument();
doc.LoadHtml(text);
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//text()"))
{
if (!String.IsNullOrWhiteSpace(node.InnerText))
sb.Append(HtmlEntity.DeEntitize(node.InnerText.Trim()) + " ");
}
return sb.ToString();
}
And you need HtmlAgilityPack
To remove the br tags:
var str = Convert.ToString(GetCurrentColumnValue("Description"));
Regex.Replace(str, #"</?\s?br\s?/?>", System.Environment.NewLine, RegexOptions.IgnoreCase);
Hi all i have code that reads from a DB and populates a string in the code behind
List<string> rows = new List<string>();
DataTable prods = common.GetDataTable("vStoreProduct", new string[] { "stpt_Name" }, "stpt_CompanyId = " + company.CompanyId.ToString() + " AND stpt_Deleted is null");
foreach (DataRow row in prods.Rows)
{
prodNames += "\"" + row["stpt_Name"].ToString().Trim() + "\",";
}
string cleanedNanes = prodNames.Substring(0, prodNames.Length - 1);
prodNames = "[" + cleanedNanes + "]";
This produces something like ["Test1","Test2"]
In javascript i have
var availableTags = '<% =prodNames %>';
alert(availableTags);
How can i access this like an array in javascript like
alert(availableTags[5]);
and get the full item at the given index.
Thanks any help would be great
Get rid of the quotes:
var availableTags = <% =prodNames %>;
With the quotes there, you're creating a JavaScript string. Without them, you've got a JavaScript array constant.
You're going to have to split the variable from .NET into a JS array.
Check out: http://www.w3schools.com/jsref/jsref_split.asp
Example based on your code:
var availableTags = '<% =prodNames %>';
var mySplitResult = availableTags .split(",");
alert(mySplitResult[1]);
I believe split() will do what you want:
var availableTagsResult = availableTags.split(",");
alert(availableTagsResult[1]) //Display element 1
This will create an array from the string which has been split on ,