Hi I have RadComboBox where I am trying to populate the dropdown options using for loop...
int last=20;
int lastitem;
for (int i=1; i < last; i++)
{
lastitem = i + 1;
categoriesCombo.Items.Add(new RadComboBoxItem(i.ToString()+ "-"+lastitem.ToString()));
}
Problem with this code is that it only displays one value the first one. Please let me know how to fix it so it can populate all the items in drop down in for loop. Thanks
I have tried with your code but not able to reproduce your issue.
Please check my code snippet.
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<telerik:RadComboBox ID="categoriesCombo" runat="server"></telerik:RadComboBox>
</form>
</body>
</html>
ASPX.CS
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int last = 20;
int lastitem;
for (int i = 1; i < last; i++)
{
lastitem = i + 1;
categoriesCombo.Items.Add(new RadComboBoxItem(i.ToString() + "-" + lastitem.ToString()));
}
}
}
OutPut:
Let me if any concern.
Related
The IsPrime method should be in a separate class in the App_Code folder, but I want to understand why this doesn't work and how to make it work.
The build error is in default.cs:
"The name 'IsPrime' does not exist in the current context"
Here is the code behind, default.cs:
using System;
public partial class _Default : System.Web.UI.Page {
protected void btnGo_Click(object sender, EventArgs e) {
lblAnswer.Text = IsPrime(Convert.ToInt32(txtNumber.Text));
}
}
Here is the markup, default.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<%# Import Namespace="System" %>
<%# Page Language="c#"%>
<script runat="server">
public partial class _Default : System.Web.UI.Page {
static public Boolean IsPrime(int num) {
Boolean isPrime = true;
int limit = num / 2;
for (int i = 2; i < limit; i++) {
if (num % i == 0) { isPrime = false; break; }
}
return isPrime;
}
}
</script>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox>
</div>
<div>
<asp:Button runat="server" ID="btnGo" OnClick="btnGo_Click" Text="Go" />
</div>
<div>
<asp:label runat="server" ID="lblAnswer" />
</div>
</form>
</body>
</html>
I changed the reference to IsPrime in Default.cs to
default_aspx.IsPrime(...)
Evidently the inline code is put in a class called default_aspx
I have this program in asp.net using C#
.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="first" runat="server">
Text Boxes
<asp:TextBox ID="txtnr" runat="server"></asp:TextBox><br />
<asp:Button ID="btnxt1" runat="server" Text="Next" onclick="btnxt1_Click"/><br />
</div>
<div id="second" runat="server">
<asp:Table ID="tbl" runat="server"></asp:Table>
<asp:Button ID="btnx2" runat="server" Text="Next" onclick="btnx2_Click"/><br />
</div>
<div id="third" runat="server">
<asp:Label ID="lblxx" runat="server" Text=""></asp:Label><br />
</div>
</form>
</body>
</html>
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
static int numr = 0;
static TableHeaderCell[] tc2;
static TextBox[] txtb;
protected void Page_Load(object sender, EventArgs e){}
protected void btnxt1_Click(object sender, EventArgs e)
{
numr = int.Parse(txtnr.Text);
TableHeaderRow tr;
tc2 = new TableHeaderCell[numr];
txtb = new TextBox[numr];
for (int i = 0; i < numr; i++)
{
tr = new TableHeaderRow();
tc2[i] = new TableHeaderCell();
txtb[i] = new TextBox();
txtb[i].Text = "w";
tc2[i].Controls.Add(txtb[i]);
tr.Controls.Add(tc2[i]);
tbl.Controls.Add(tr);
}
}
protected void btnx2_Click(object sender, EventArgs e)
{
for (int i = 0; i < numr; i++)
lblxx.Text += txtb[i].Text+"<br/>";
}
}
Program steps:
enter number of text-boxes to appear (say = 4) and click 'Next'
four text-boxes will appear (the program sets the value of textbox = "w",to understand the problem)
user can set other value for the text for the four text boxes (say: 1 , 2 , 3 , 4) then click next
finally, the program print the values of text boxes, but the problem is the program
will print: wwww not "1234" :( ??
How to fix this problem??
The problem is due to the fact that dynamic controls (like yours) do not automatically maintain their state after a post back and you should handle it on your own.
Please follow this link for a very similar question and then this link for the corresponding solution.
<asp:CheckBox ID="CheckBox1" OnCheckedChanged="CheckBox1_CheckedChanged" runat="server" Text="Toggle Visibility" AutoPostBack="true"/>
and an Ajax toggle button extander:
<ajaxToolkit:ToggleButtonExtender ID="Ext1" CheckedImageAlternateText="View" TargetControlID="CheckBox1" runat="server" CheckedImageUrl="~/Images/Others/view.png" UncheckedImageAlternateText="Hide" UncheckedImageUrl="~/Images/Others/hide.png" ImageWidth="32" ImageHeight="24" ></ajaxToolkit:ToggleButtonExtender>
But it is not working.
The page is loading but with the default checkboxes.
Thanks for any help
you can try like this.....
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
CheckBox myCB = new CheckBox();
myCB.ID = "myCB";
myCB.Checked = true;
myCB.Text = "I like ASP.NET";
Panel1.Controls.Add(myCB);
AjaxControlToolkit.ToggleButtonExtender myTBE = new AjaxControlToolkit.ToggleButtonExtender();
myTBE.TargetControlID = "myCB";
myTBE.CheckedImageUrl = "ToggleButton_Checked.gif";
myTBE.UncheckedImageUrl = "ToggleButton_Unchecked.gif";
myTBE.ImageHeight = 19;
myTBE.ImageWidth = 19;
Panel1.Controls.Add(myTBE);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</form>
</body>
</html>
i'm using asp.net web form fx3.5 and i'm trying to get my server-side string array into my javascript. i found a simple example that claims to work but it doesn't for me. temp variable is not recognized in ().Serialize(temp);
Here's the reference article
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ShelterExpress.UserInterface.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="c#">
string[] temp;
int lengthOfTemp;
public string tempJSON = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(temp);
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<script runat="server" language="c#">
string[] temp;
int lengthOfTemp;
public string tempJSON;
protected override void OnLoad(EventArgs e)//you have to initialize your temp and tempJSON in a method
{
base.OnLoad(e);
temp = new string[] { "Hi", ",", "ojlovecd" };//Initialize your temp here
tempJSON = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(temp);
}
</script>
How we can filter the results according with the input of of a textbox like Google search.
i.e, If i enter "alaska airlines", then it filtered and showed result according with our input. How it possible. Please help me. thanks in advnce..
If I understand correctly you want some form of autocomplete as the user types in your input box.
To achieve this you should use ajax, and the ASP.Net Ajax Toolkit might be what you are looking for. Check out the sample and docs at http://www.asp.net/ajax/ajaxcontroltoolkit/samples/autocomplete/autocomplete.aspx.
Here's a sample for VS2010 and using ASP.Net Toolkit 4.
Markup
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox runat="server" ID="myTextBox" autocomplete="off" />
<asp:autocompleteextender runat="server" behaviorid="AutoCompleteEx" id="autoComplete1"
targetcontrolid="myTextBox" servicepath="AutoComplete.asmx" servicemethod="GetCompletionList"
minimumprefixlength="2" completioninterval="1000" enablecaching="true" completionsetcount="20"></asp:autocompleteextender>
</div>
</form>
</body>
</html>
AutoComplete.asmx.cs
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
public AutoComplete()
{
}
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
if (prefixText.Equals("xyz"))
{
return new string[0];
}
Random random = new Random();
List<string> items = new List<string>(count);
for (int i = 0; i < count; i++)
{
char c1 = (char)random.Next(65, 90);
char c2 = (char)random.Next(97, 122);
char c3 = (char)random.Next(97, 122);
items.Add(prefixText + c1 + c2 + c3);
}
return items.ToArray();
}
}
On search click event bind the grid or any controls where you want to populate the result through the database query using like keyword by passing the textbox value as input parameter