Vinit Patel

If you have CheckboxList like

0 – 5

5 – 10

10 – 15

15 – 20

25+

If you had selected multiple like 5 – 10 & 10 – 15 then Values be like 5 – 15.

So, Here is the code for that,

protected void btn1_Click(object sender, EventArgs e)
{
String values = “”;
for (int i = 0; i < cbl1.Items.Count; i++)
{
if (cbl1.Items[i].Selected)
{
values += cbl1.Items[i].Value + “,”;
}
}
values = values.TrimEnd(‘,’);
lbl1.Text = Combine(values);
}

 

//Function which actually returns the combine values

public string Combine(string input)
{
//First remove all the white spaces
string result = input.Replace(” “, string.Empty);
//Split on each ,
string[] results = result.Split(‘,’);
//Now split on each –
List<string> final = new List<string>();
//Split on each dash
foreach (string s in results)
final.AddRange(s.Split(‘-‘));
//Remove duplicates
final = final.Distinct().ToList();
//Return the first and the last element
return string.Format(“{0} – {1}”, final.First(), final.Last());
}

 

Advertisements

Hi,

 

The below code is for replace the specified attribute from the html.

protected override void Render(HtmlTextWriter writer)
{
using (System.IO.MemoryStream msOur = new System.IO.MemoryStream())
{
using (System.IO.StreamWriter swOur = new System.IO.StreamWriter(msOur))
{
HtmlTextWriter ourWriter = new HtmlTextWriter(swOur);
base.Render(ourWriter);
ourWriter.Flush();
msOur.Position = 0;
using (System.IO.StreamReader oReader = new System.IO.StreamReader(msOur))
{

string sTxt = oReader.ReadToEnd();
sTxt = sTxt.Replace(“rules=\”all\””, ” “);
Response.Write(sTxt);
oReader.Close();
}
}
}
}

Hi,

If you have the Data in Sql table like

Value

15

17

 

Now, If you want to print the values like $15 and $17. So you will have to do like this…

SELECT LEFT(‘$’ + CONVERT(VARCHAR, CAST(‘15.00’ AS MONEY), 1), LEN(‘$’+ CONVERT(VARCHAR, CAST(‘15.00’ AS MONEY), 1)) – 3)

Tags: ,

Hi,

If, you want to remove the textbox auto-complete history from the browser,

then You have to set two properties for text box in aspx File.

Autocomplete=”Off” and AutoCompleteType=”Disabled”

This will dont prompt any previous values of textbox which you entered in the past.

From,

Vinit.

Hi,

If I want to select only limited(2) items from the listbox then using Jquery use the below code,

<head id=”Head1″ >
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js”></script&gt;

</head>
<body>
<form runat=”server”>
<asp:ListBox ID=”ListBox1″ runat=”server” SelectionMode=”Multiple”>
<asp:ListItem Text=”Item1″></asp:ListItem>
<asp:ListItem Text=”Item2″></asp:ListItem>
<asp:ListItem Text=”Item3″></asp:ListItem>
<asp:ListItem Text=”Item4″></asp:ListItem>
</asp:ListBox>
</form>
</body>
<script type=”text/javascript”>
$(‘#<%= ListBox1.ClientID %>’).change(function()
{
if ($(this).find(‘option:selected’).length > 2)
{
this.options[this.selectedIndex].selected = false;
}
;
});
</script>

</html>

Using Javascript

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head id=”Head1″ >

<script type=”text/javascript”>
function test()
{
var selectedCount = 0;
var listBox = document.getElementById(‘<%= ListBox1.ClientID %>’);
var i = 0;
do
{
if (listBox.options[i].selected)
{
selectedCount++;
if (selectedCount > 2)
{
listBox.options[i].selected = false;
break;
}
}
i++;

} while (i < listBox.options.length)
}
</script>

</head>
<body>
<form runat=”server”>
<asp:ListBox ID=”ListBox1″ runat=”server” onchange=”test()” SelectionMode=”Multiple”>
<asp:ListItem Text=”Item1″></asp:ListItem>
<asp:ListItem Text=”Item2″></asp:ListItem>
<asp:ListItem Text=”Item3″></asp:ListItem>
<asp:ListItem Text=”Item4″></asp:ListItem>
</asp:ListBox>
</form>
</body>
</html>

For Linq to Sql and entity reference you can check the Rick Strahl’s Blog.

Here, is the Link.

http://west-wind.com/weblog/posts/137000.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+RickStrahl+%28Rick+Strahl%27s+WebLog%29&utm_content=Google+Reader

This is really good.

Calendar

November 2017
M T W T F S S
« Jan    
 12345
6789101112
13141516171819
20212223242526
27282930  

Stats Of Blog

  • 7,054 hits

Cluster Map