function stopPropagation(e,CheckBoxControl,ComboBoxControl)
{
// Calling the CheckChanged function (parameter: CheckBox Control)
CheckChanged(CheckBoxControl,ComboBoxControl);
// To keep the dropdown open
e.cancelBubble = true;
if (e.stopPropagation)
{
e.stopPropagation();
}
}
// To set the ComboBox Text with the Checked ComboBox Text
function CheckChanged(CheckBoxControl,ComboBoxControl)
{
var combo = ~~%=RadComboBox1.ClientID %~~~;
var str="";
for(i=0; i~~combo.Items.length; i++)
{
var controlid="RadComboBox1_c"+eval(i) + "_CheckBox";
var control=document.getElementById(controlid);
if(control.checked)
{
str+=combo.Items[i].Text+";"
}
else
continue;
}
combo.SetText(str);
}
In the RadComboBox ItemTemplate
~~ItemTemplate~~~
~~asp:CheckBox runat="server" ID="CheckBox" onclick="stopPropagation(event,this,'RadComboBox1');"
Text='~~%# Eval("Text") %~~~' /~~~ ~~/ItemTemplate~~~
Please replace "~~" with less than symbol and replace "~~~" with greater than symbol
Friday, October 12, 2007
Wednesday, September 26, 2007
"Remember User Login" using ASP.NET,C#.NET
// Write this code in the Login button click
// Store the user's username and password in a cookie when checkbox Remember Me checked
if (chkRememberLogin.Checked == true)
{
HttpCookie myCookie = new HttpCookie("myCookie");
Response.Cookies.Remove("myCookie");
Response.Cookies.Add(myCookie);
myCookie.Values.Add("UserName", this.txtUserID.Text.ToString());
myCookie.Values.Add("PassWord", this.txtPassword.Text.ToString());
DateTime dtExpiry = DateTime.Now.AddMonths(1); //you can add years and months too here Response.Cookies["myCookie"].Expires = dtExpiry;
}
// Write this code in the Form Load()
if (!IsPostBack)
{
if (Request.Cookies["myCookie"] != null)
{
HttpCookie myCookie = Request.Cookies.Get("myCookie");
this.txtUserID.Text = myCookie.Values["UserName"].ToString();
this.txtPassword.Attributes.Add("Value", myCookie.Values["PassWord"].ToString());
}
}
// Store the user's username and password in a cookie when checkbox Remember Me checked
if (chkRememberLogin.Checked == true)
{
HttpCookie myCookie = new HttpCookie("myCookie");
Response.Cookies.Remove("myCookie");
Response.Cookies.Add(myCookie);
myCookie.Values.Add("UserName", this.txtUserID.Text.ToString());
myCookie.Values.Add("PassWord", this.txtPassword.Text.ToString());
DateTime dtExpiry = DateTime.Now.AddMonths(1); //you can add years and months too here Response.Cookies["myCookie"].Expires = dtExpiry;
}
// Write this code in the Form Load()
if (!IsPostBack)
{
if (Request.Cookies["myCookie"] != null)
{
HttpCookie myCookie = Request.Cookies.Get("myCookie");
this.txtUserID.Text = myCookie.Values["UserName"].ToString();
this.txtPassword.Attributes.Add("Value", myCookie.Values["PassWord"].ToString());
}
}
Tuesday, September 25, 2007
Select Distinct columns from a DataTable
public static DataTable SelectDistinct(DataTable SourceTable, params string[] FieldNames)
{
object[] lastValues;
DataTable newTable;
DataRow[] orderedRows;
if (FieldNames == null FieldNames.Length == 0)
throw new ArgumentNullException("FieldNames");
lastValues = new object[FieldNames.Length];
newTable = new DataTable();
foreach (string fieldName in FieldNames)
newTable.Columns.Add(fieldName, SourceTable.Columns[fieldName].DataType);
orderedRows = SourceTable.Select("", string.Join(", ", FieldNames));
foreach (DataRow row in orderedRows)
{
if (!fieldValuesAreEqual(lastValues, row, FieldNames))
{
newTable.Rows.Add(createRowClone(row, newTable.NewRow(), FieldNames));
setLastValues(lastValues, row, FieldNames);
}
}
return newTable;
}
{
object[] lastValues;
DataTable newTable;
DataRow[] orderedRows;
if (FieldNames == null FieldNames.Length == 0)
throw new ArgumentNullException("FieldNames");
lastValues = new object[FieldNames.Length];
newTable = new DataTable();
foreach (string fieldName in FieldNames)
newTable.Columns.Add(fieldName, SourceTable.Columns[fieldName].DataType);
orderedRows = SourceTable.Select("", string.Join(", ", FieldNames));
foreach (DataRow row in orderedRows)
{
if (!fieldValuesAreEqual(lastValues, row, FieldNames))
{
newTable.Rows.Add(createRowClone(row, newTable.NewRow(), FieldNames));
setLastValues(lastValues, row, FieldNames);
}
}
return newTable;
}
Friday, September 21, 2007
Programatically highlight a row in Telerik RadGridView [ WinForms]
There are two ways to programmatically highlight a row:
Use the Row's IsCurrent property:
this.radGridView1.Rows[RowIndex].IsCurrent = true;
Use the GridViewInfo's CurrentRow property:
this.radGridView1.MasterGridViewInfo.CurrentRow = this.radGridView1.Rows[RowIndex];
Use the Row's IsCurrent property:
this.radGridView1.Rows[RowIndex].IsCurrent = true;
Use the GridViewInfo's CurrentRow property:
this.radGridView1.MasterGridViewInfo.CurrentRow = this.radGridView1.Rows[RowIndex];
Tuesday, September 18, 2007
Validation in the grid cells
//Validating the Order column [Only numeric values allowed]
private void DataGrid1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
int newinteger;
if (e.ColumnIndex == 4)
{
bool Check = int.TryParse(e.FormattedValue.ToString(), out newinteger);
if (Check == false && e.FormattedValue.ToString() != "")
{
MessageBox.Show("Enter numeric value");
e.Cancel = true;
}
}
}
private void DataGrid1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
int newinteger;
if (e.ColumnIndex == 4)
{
bool Check = int.TryParse(e.FormattedValue.ToString(), out newinteger);
if (Check == false && e.FormattedValue.ToString() != "")
{
MessageBox.Show("Enter numeric value");
e.Cancel = true;
}
}
}
Subscribe to:
Posts (Atom)