string str = "A,B,C,D,"; //Declare a arraylist for getting comma separated string ArrayList arr = new ArrayList(); //check wether the re is comma in the end of the string if (str.Trim().EndsWith(",")) { str = str.Substring(0, str.Length - 1); } //split the comma separated string into arraylist arr.AddRange(str.Split(',')); //loop through the arraylist items & add the item to Dropdownlist for (int i = 0; i < arr.Count; i++) { DropDownList1.Items.Insert(i, new ListItem(arr[i].ToString(), (i + 1).ToString())); }
Wednesday, 27 November 2013
Bind Comma Separated string Values into Dropdown
Sunday, 24 November 2013
by entering percentage on textbox it will calculate grid column percentage and add that percentage amount with that column amount and stored it to another column for every line item of the grid
function fcnDistribution() {
// ClearValues();
var gridrowLength = $("span[id$=lblSCAmount]").length;
var Percentage = $("[id$='txtServiceChargePerc']").val();
// alert("Percentage" + Percentage);
$("span[id$=lblSCAmount]").each(function () {
var id = $(this).attr('id');
var rowId = id.substr(id.length - 17).substr(0, 5);
var ScAmount = Filtervalue($(this));
// alert("SC Amount" + ScAmount);
// alert(parseFloat(ScAmount) +"\r\n"+ parseFloat(Percentage.replace("%", '')))
//if()
{
var perCAmount = parseFloat((parseFloat(ScAmount) * parseFloat(Percentage.replace("%", ''))) / 100);
// alert("perCAmount" + perCAmount);
var totalamt = parseFloat(perCAmount) + parseFloat(ScAmount);
//alert("total" + totalamt);
}
var txtChargeAmountId = $("[id$=" + rowId + "_txtChargeAmount]");
//alert("txtAmountId" + txtChargeAmountId.val());
var ChargeAmt = "$" + parseFloat(totalamt, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString();
txtChargeAmountId.val(ChargeAmt);
});
}
function ValidatePercent() {
var ServiceChargePerc = $("[id$='txtServiceChargePerc']");
$(ServiceChargePerc).keydown(function (event) {
// onlyNumbers(event);
$(ServiceChargePerc).focusout(function (event) {
var percent = $(ServiceChargePerc).val().replace("$", " ");
if (percent.indexOf('%') == -1 && $(ServiceChargePerc).val().length != 0)
$(ServiceChargePerc).val(parseFloat(percent).toFixed(2) + "%");
});
});
function Filtervalue(input) {
var Output = input.text();
// alert(1);
Output = Output.replace("$", ''); //Replace "$"(Doller) with empty string
Output = Output.replace(/,/g, ''); //Replace n no of ","(camas) with empty string
return Output;
}
------------ textbox focus out event call function
function MouseOutvalidationReceiptHeader() {
var txtAmountReceipt = $("[id$='txtServiceChargePerc']");
txtAmountReceipt.focusout(function () {
if ($.trim(txtAmountReceipt.val()) != "") {
fcnDistribution();
ValidatePercent();
}
});
}
----------call method on postback and ready
$(document).ready(function () {
ValidatePercent();
WOChargesFocusOutValid();
MouseOutvalidationReceiptHeader();
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function (s, e) {
ValidatePercent();
MouseOutvalidationReceiptHeader();
$('form').dirtyForms();
});
// ClearValues();
var gridrowLength = $("span[id$=lblSCAmount]").length;
var Percentage = $("[id$='txtServiceChargePerc']").val();
// alert("Percentage" + Percentage);
$("span[id$=lblSCAmount]").each(function () {
var id = $(this).attr('id');
var rowId = id.substr(id.length - 17).substr(0, 5);
var ScAmount = Filtervalue($(this));
// alert("SC Amount" + ScAmount);
// alert(parseFloat(ScAmount) +"\r\n"+ parseFloat(Percentage.replace("%", '')))
//if()
{
var perCAmount = parseFloat((parseFloat(ScAmount) * parseFloat(Percentage.replace("%", ''))) / 100);
// alert("perCAmount" + perCAmount);
var totalamt = parseFloat(perCAmount) + parseFloat(ScAmount);
//alert("total" + totalamt);
}
var txtChargeAmountId = $("[id$=" + rowId + "_txtChargeAmount]");
//alert("txtAmountId" + txtChargeAmountId.val());
var ChargeAmt = "$" + parseFloat(totalamt, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString();
txtChargeAmountId.val(ChargeAmt);
});
}
function ValidatePercent() {
var ServiceChargePerc = $("[id$='txtServiceChargePerc']");
$(ServiceChargePerc).keydown(function (event) {
// onlyNumbers(event);
$(ServiceChargePerc).focusout(function (event) {
var percent = $(ServiceChargePerc).val().replace("$", " ");
if (percent.indexOf('%') == -1 && $(ServiceChargePerc).val().length != 0)
$(ServiceChargePerc).val(parseFloat(percent).toFixed(2) + "%");
});
});
function Filtervalue(input) {
var Output = input.text();
// alert(1);
Output = Output.replace("$", ''); //Replace "$"(Doller) with empty string
Output = Output.replace(/,/g, ''); //Replace n no of ","(camas) with empty string
return Output;
}
------------ textbox focus out event call function
function MouseOutvalidationReceiptHeader() {
var txtAmountReceipt = $("[id$='txtServiceChargePerc']");
txtAmountReceipt.focusout(function () {
if ($.trim(txtAmountReceipt.val()) != "") {
fcnDistribution();
ValidatePercent();
}
});
}
----------call method on postback and ready
$(document).ready(function () {
ValidatePercent();
WOChargesFocusOutValid();
MouseOutvalidationReceiptHeader();
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function (s, e) {
ValidatePercent();
MouseOutvalidationReceiptHeader();
$('form').dirtyForms();
});
Jquery for Grid textbox validation with required field
function ValidateElement(element) {
if ($(element).val() == '') {
$(element).css("border", "1px solid red");
}
$(element).hover(function () {
if ($(element).val() == '') {
qtipPopup(element, "Required Field");
}
},
function () {
if ($(element).data("qtip")) $(element).qtip("destroy");
});
$(element).focusout(function () {
if ($(element).val() != '') {
$(element).css("border", "");
}
else {
$(element).css("border", "1px solid red");
}
});
}
function qtipPopup(element, message) {
$.fn.qtip.zindex = "999";
if ($(element).data("qtip")) $(element).qtip("destroy");
$(element).css("border", "1px solid red");
$(element).qtip({
overwrite: false, content: message,
position: { my: 'bottomLeft', at: 'leftTop' },
show: { event: 'focus' },
hide: { event: 'focusout' },
style: { classes: 'ui-tooltip-green', name: 'dark' }
});
}
function GridTextValidation() {
var gridValid = true;
var loopStart = ($("[id$='grdWorkOrderCharges']").find('tr').length > 9) ? 0 : 1;
for (var i = loopStart; i < $("[id$='grdWorkOrderCharges']").find('tr').length; i++) {
var rowData1 = $("[id$='grdWorkOrderCharges']").find('tr')[i];
var ChargeAccountInfo = $(rowData1).find('input[id$=txtChargeAccount]');
if ($(ChargeAccountInfo) != null) {
if ($(ChargeAccountInfo).val().length > 0) {
if ($(ChargeAccountInfo).data("qtip"))
$(ChargeAccountInfo).qtip("destroy");
}
else {
ValidateElement($(ChargeAccountInfo));
gridValid = false;
}
}
}
return gridValid;
}
Grid total column values calculate and display into the label
function AddTotal() {
var tot = 0.00;
$("[id$='txtChargeAmount']").each(function () {
var sum = $(this).val();
// alert('sum' + sum);
sum = sum.replace("$", ''); //Replace "$"(Doller) with empty string
sum = sum.replace(/,/g, ''); //Replace n no of ","(camas) with empty string
if (isNaN(sum)) {
//alert(sum + ' is not a number');
}
else {
if (sum == "") {
sum = 0;
}
tot += parseFloat(sum);
}
});
//Display the total sum of Values to "txtAmountReceipt" control
var Total = '$' + tot.toFixed(2);
$("[id$='lblTotalAmount']").text(Total);
// $("[id$='hdnTotalAmount']").val(Total);
}
var tot = 0.00;
$("[id$='txtChargeAmount']").each(function () {
var sum = $(this).val();
// alert('sum' + sum);
sum = sum.replace("$", ''); //Replace "$"(Doller) with empty string
sum = sum.replace(/,/g, ''); //Replace n no of ","(camas) with empty string
if (isNaN(sum)) {
//alert(sum + ' is not a number');
}
else {
if (sum == "") {
sum = 0;
}
tot += parseFloat(sum);
}
});
//Display the total sum of Values to "txtAmountReceipt" control
var Total = '$' + tot.toFixed(2);
$("[id$='lblTotalAmount']").text(Total);
// $("[id$='hdnTotalAmount']").val(Total);
}
Tuesday, 29 October 2013
grid having button click event code behind retrive grid selected checkbox values
string ids = string.Empty;
ids = (from GridViewRow gvSingleSavingsBookRow in grvVendorProperties.Rows
let rowSelected = (CheckBox)gvSingleSavingsBookRow.FindControl("chkVendorProperties")
let myId = (HiddenField)gvSingleSavingsBookRow.FindControl("HiddenEntityID")
where (null != rowSelected) && (null != myId)
&& rowSelected.Checked
select myId).Aggregate(ids, (current, myId) =>
string.Format("{0}{1}{2}", current, myId.Value.Trim(), ","));
-----------------------------------------------------------------------------
for (int rowIndex = 0; rowIndex < grvVendorProperties.Rows.Count; rowIndex++)
{
TextBox txtExpenseAccount = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtExpenseAccount");
TextBox txtInitialBalance = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtInitialBalance");
Button btnExpenseAccount = (Button)grvVendorProperties.Rows[rowIndex].FindControl("btnExpenseAccount");
TextBox txtEffectiveDate = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtEffectiveDate");
TextBox txtReceiptAccount = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtReceiptAccount");
Button btnReceiptAccount = (Button)grvVendorProperties.Rows[rowIndex].FindControl("btnReceiptAccount");
CheckBox chk = (CheckBox)grvVendorProperties.Rows[rowIndex].FindControl("chkVendorProperties");
if (chk.Checked == true)
{
chk.Checked = true;
txtExpenseAccount.Enabled = true;
txtInitialBalance.Enabled = true;
btnExpenseAccount.Enabled = true;
txtEffectiveDate.Enabled = true;
txtReceiptAccount.Enabled = true;
btnReceiptAccount.Enabled = true;
}
else
chk.Checked = false;
}
grid row having button and after click particulare row button event find entire grid checkbox selected rows only using linq list
List<int> listIndex = CheckedRows.AsEnumerable().Select(f => f.RowIndex).ToList();
foreach (int rowIndex in listIndex)
{
TextBox txtExpenseAccount = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtExpenseAccount");
TextBox txtInitialBalance = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtInitialBalance");
Button btnExpenseAccount = (Button)grvVendorProperties.Rows[rowIndex].FindControl("btnExpenseAccount");
TextBox txtEffectiveDate = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtEffectiveDate");
TextBox txtReceiptAccount = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtReceiptAccount");
Button btnReceiptAccount = (Button)grvVendorProperties.Rows[rowIndex].FindControl("btnReceiptAccount");
txtExpenseAccount.Enabled = true;
txtInitialBalance.Enabled = true;
btnExpenseAccount.Enabled = true;
txtEffectiveDate.Enabled = true;
txtReceiptAccount.Enabled = true;
btnReceiptAccount.Enabled = true;
}
Monday, 28 October 2013
Grid view button click dont want to referesh grid
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:Button ID="btnExpenseAccount" runat="server" CssClass="button_small_tgrid" Text="..."
Enabled="false" OnClick="btnExpenseAccount_Click" />
</ContentTemplate>
</asp:UpdatePanel>
protected void btnExpenseAccount_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger { ControlID = btn.UniqueID, EventName = "click" });
}
<ContentTemplate>
<asp:Button ID="btnExpenseAccount" runat="server" CssClass="button_small_tgrid" Text="..."
Enabled="false" OnClick="btnExpenseAccount_Click" />
</ContentTemplate>
</asp:UpdatePanel>
protected void btnExpenseAccount_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger { ControlID = btn.UniqueID, EventName = "click" });
}
Subscribe to:
Posts (Atom)