AmCharts not displayed when adding website to local IIS - asp.net

I created asp.net webform project including amcharts using visual studio. Everything works when I run project. But when I publish it on a local IIS (current version is 7 - windows 7 64 bit) it is not displayed. I googled a bit but not found a solution yet. (One of them was Setting up IIS for correctly handling SVG files, but it also didn't help.) Is anybody faced this problem?

I use Chrome. When I run project it works. But not works after deploying to IIS.
Here is code I reduced additional parts.
Visual basic.Net code that gets data from SQL and creates string of JS function
Protected Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
comm.CommandText = "Select DateMeasr, data1, data2 from dbo.Measurements where DateMeasr>'2017-06-13 12:04:30' and DateMeasr<'2017-06-13 17:00:00' Order by DateMeasr"
If conn.State <> ConnectionState.Open Then conn.Open()
da.Fill(dtC)
If dtC.Rows.Count > 0 Then
DataCollect()
End If
End Sub
Protected Sub DataCollect()
Dim sb As New StringBuilder
Dim strtime As DateTime
sb.Append("<script type=""text/javascript"">")
sb.Append("function generateChartData() {")
For i = 0 To dtC.Rows.Count - 1
strtime = CDate(dtC.Rows(i).Item(0))
sb.Append("var newDate = new Date(" + strtime.Year.ToString + ", " + (strtime.Month - 1).ToString + ", " + strtime.Day.ToString + ", " + strtime.Hour.ToString + ", " + strtime.Minute.ToString + ", " + strtime.Second.ToString + ");")
sb.Append("var data1 = " + dtC.Rows(i).Item(1).ToString + ";")
sb.Append("var data2 = " + dtC.Rows(i).Item(2).ToString + ";")
sb.Append("chartData1.push({")
sb.Append("date: newDate,")
sb.Append("data1: data1,")
sb.Append("data2: data2")
sb.Append("});")
Next
sb.Append("}")
sb.Append("</script>")
ScriptManager.RegisterStartupScript(btn1, btn1.GetType, "teststring", sb.ToString, False)
End Sub
Javascript function to create Amchart
<script type="text/javascript">
var chart1;
var chartData1 = [];
AmCharts.ready(function () {
chart1 = new AmCharts.AmSerialChart();
chart1.dataProvider = chartData1;
chart1.dataDateFormat = "YYYY-MM-DD, JJ:NN:SS";
chart1.categoryField = "date";
chart1.rotate = true;
chart1.autoMargins = false;
chart1.marginLeft = 85;
chart1.marginTop = 200;
chart1.pathToImages = "https://www.amcharts.com/lib/3/images/";
chart1.synchronizeGrid = true; // this makes all axes grid to be at the same intervals
// AXES
// category
var categoryAxis1 = chart1.categoryAxis;
categoryAxis1.parseDates = true; // as our data is date-based, we set parseDates to true
categoryAxis1.minPeriod = "ss";
categoryAxis1.minorGridEnabled = true;
categoryAxis1.axisColor = "#DADADA";
categoryAxis1.twoLineMode = true;
categoryAxis1.dateFormats = [{
period: 'fff',
format: 'JJ:NN:SS'
}, {
period: 'ss',
format: 'JJ:NN:SS'
}, {
period: 'mm',
format: 'JJ:NN'
}, {
period: 'hh',
format: 'JJ:NN'
}, {
period: 'DD',
format: 'DD'
}, {
period: 'WW',
format: 'DD'
}, {
period: 'MM',
format: 'MMMM'
}, {
period: 'YYYY',
format: 'YYYY'
}];
// first value axis (on the left)
var valueAxis1 = new AmCharts.ValueAxis();
valueAxis1.offset = 175;
valueAxis1.position = "right";
valueAxis1.axisColor = "#04a016";
valueAxis1.axisThickness = 2;
chart1.addValueAxis(valueAxis1);
var valueAxis2 = new AmCharts.ValueAxis();
valueAxis2.offset = 125;
valueAxis2.position = "right";
valueAxis2.axisColor = "#ea0e19";
valueAxis2.axisThickness = 2;
chart1.addValueAxis(valueAxis2);
// GRAPHS
// first graph
var graph1 = new AmCharts.AmGraph();
graph1.valueAxis = valueAxis1; // we have to indicate which value axis should be used
graph1.lineColor = valueAxis1.axisColor;
graph1.title = "data1graph";
graph1.valueField = "data1";
graph1.hideBulletsCount = 30;
graph1.bulletBorderThickness = 1;
graph1.lineThickness = 2;
chart1.addGraph(graph1);
var graph2 = new AmCharts.AmGraph();
graph2.valueAxis = valueAxis2; // we have to indicate which value axis should be used
graph2.lineColor = valueAxis2.axisColor;
graph2.title = "data2graph";
graph2.valueField = "data2";
graph2.hideBulletsCount = 30;
graph2.bulletBorderThickness = 1;
graph2.lineThickness = 2;
chart1.addGraph(graph2);
// CURSOR
var chartCursor1 = new AmCharts.ChartCursor();
chartCursor1.cursorAlpha = 0.1;
chartCursor1.fullWidth = true;
chartCursor1.valueLineBalloonEnabled = true;
chart1.addChartCursor(chartCursor1);
// SCROLLBAR
var chartScrollbar1 = new AmCharts.ChartScrollbar();
chart1.addChartScrollbar(chartScrollbar1);
// LEGEND
var legend1 = new AmCharts.AmLegend();
legend1.markerLabelGap = 3;
legend1.spacing = 1;
legend1.position = "absolute";
legend1.position = "top";
chart1.addLegend(legend1);
});
function clicktodrawchart()
{
generateChartData();
chart1.write("chartdiv1");
}
</script>
Asp.net tags for buttons and div that show chart
<div>
<ajaxToolkit:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
<HeaderTemplate>
Charts<br />
</HeaderTemplate>
<ContentTemplate>
<br />
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button runat="server" ID="btn1" Text="Get data from DB" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<input id="btnforchart" value="Click to draw charts" type="button" style="color: black; font-size:15px; padding:4px;" onclick="clicktodrawchart()" />
<div id="chartdiv1" style="width: 400px; height: 1000px; position: absolute; top: 260px; left: 40px; border: 2px solid #9ccfed;"></div>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
</div>

Related

Asp.NET gridview showing delete option to the latest row only.And same must be able to view on selected index change of radio button with data fill

Actually I'm using GridView for fixed and percentage based commission and I'm hiding same on selected index change of radio button.
On page load I'm showing only delete option at latest row only which work properly. The problem comes when I'm trying to change the selected Index of the commission based radio button and at the same time binding data to the GridView from database accordingly.
public void LoadGrid(){
try {
DataTable DtLoadAgentCommission = new DataTable();
DtLoadAgentCommission.Columns.Add("RowNumber");
DtLoadAgentCommission.Columns.Add("MinCount");
DtLoadAgentCommission.Columns.Add("MaxCount");
DtLoadAgentCommission.Columns.Add("AgentWiseCommission");
DtLoadAgentCommission.Columns.Add("FixedAmount");
DtLoadAgentCommission.Columns.Add("CommissionType");
DtLoadAgentCommission.Columns.Add("CommissionDescription");
DataRow dr = DtLoadAgentCommission.NewRow();
dr["RowNumber"] = "1";
dr["MinCount"] = string.Empty;
dr["MaxCount"] = string.Empty;
dr["CommissionType"] = string.Empty;
dr["AgentWiseCommission"] = string.Empty;
dr["FixedAmount"] = string.Empty;
dr["CommissionDescription"] = string.Empty;
DtLoadAgentCommission.Rows.Add(dr);
grvViewFixedAgentCommisionConfiguration.DataSource = DtLoadAgentCommission;
grvViewFixedAgentCommisionConfiguration.DataBind();
ViewState["ViewAgentCommission"] = DtLoadAgentCommission;
} catch (Exception Ex) {
_clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}
protected void grvViewFixedAgentCommisionConfiguration_RowDataBound(object sender, GridViewRowEventArgs e) {
try {
if (e.Row.RowType == DataControlRowType.DataRow) {
RowIndexFromGV = RowIndexFromGV + 1;
TextBox txtFixedAmountTabMinCount = (TextBox) e.Row.FindControl("txtFixedAmountTabMinCount");
TextBox txtMaxCount = (TextBox) e.Row.FindControl("txtMaxCount");
DropDownList ddlCommissionType = (DropDownList) e.Row.FindControl("ddlCommissionType");
TextBox txtInterest = (TextBox) e.Row.FindControl("txtInterest");
TextBox txtFixedAmount = (TextBox) e.Row.FindControl("txtFixedAmount");
Label lblcommissiontypeID = (Label) e.Row.FindControl("lblcommissiontypeID");
LinkButton btnRemoveAgentCommission = (LinkButton) e.Row.FindControl("btnRemoveAgentCommission");
string checkpostrowindex = e.Row.RowIndex.ToString();
if (!string.IsNullOrEmpty(hdfremovecommIDs.Value)) {
int removedId = Convert.ToInt32(hdfremovecommIDs.Value) - 1;
if (removedId.ToString().Equals(checkpostrowindex)) {
btnRemoveAgentCommission.Visible = true;
}
} else
if (RowsCountFromGV == RowIndexFromGV) {
btnRemoveAgentCommission.Visible = true;
}
if (rbtnFixedAmountTab1.SelectedValue == "1") {
grvViewFixedAgentCommisionConfiguration.Columns[4].Visible = false;
grvViewFixedAgentCommisionConfiguration.Columns[5].Visible = true;
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "alert", string.Format("alert('Commission slab can be change only on 1st Date of month.')"), true);
} else {
grvViewFixedAgentCommisionConfiguration.Columns[4].Visible = true;
grvViewFixedAgentCommisionConfiguration.Columns[5].Visible = false;
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "alert", string.Format("alert('Commission slab can be change only on 1st Date of month.')"), true);
}
} catch (Exception Ex) {
_clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}
}
protected void rbtnFixedAmountTab1_SelectedIndexChanged(object sender, EventArgs e) {
try {
if (DateTime.Now.ToString("dd") == Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"])) {
fillAgentCommisionData();
if (rbtnFixedAmountTab1.SelectedValue.Equals("1")) {
grvViewFixedAgentCommisionConfiguration.Columns[4].Visible = false;
grvViewFixedAgentCommisionConfiguration.Columns[5].Visible = true;
} else if (rbtnFixedAmountTab1.SelectedValue.Equals("2")) {
grvViewFixedAgentCommisionConfiguration.Columns[4].Visible = true;
grvViewFixedAgentCommisionConfiguration.Columns[5].Visible = false;
}
} else {
if (rbtnFixedAmountTab1.SelectedIndex == 1) {
} else {
}
string DateValue = Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"]);
Response.Write("<script language='javascript'>window.alert('Commission type can be change only on " + DateValue + " Date of month. " + "');</script>");
} catch (Exception ex) {
AppLog.ErrorLog(sender, ex);
ScriptManager.RegisterStartupScript(this.Page, typeof(string), "msg", "alert('Alarm: Contact system administrator');", true);
}
}
}
public void fillAgentCommisionData() {
try {
DataTable AgentCommisionConfiguration = new DataTable();
AgentCommisionConfiguration = MobilePortalProcess.GetAgentCommisionConfigurationDetails();
if (AgentCommisionConfiguration.Rows.Count > 0) {
if (rbtnFixedAmountTab1.SelectedValue.Equals("0") || rbtnFixedAmountTab1.SelectedValue.Equals("1") || rbtnFixedAmountTab1.SelectedValue.Equals("2")) {
} else {
RowsCountFromGV = AgentCommisionConfiguration.Rows.Count;
rbtnFixedAmountTab1.Items.FindByText(AgentCommisionConfiguration.Rows[0]["CommissionDescription"].ToString()).Selected = true;
}
grvViewFixedAgentCommisionConfiguration.DataSource = AgentCommisionConfiguration;
grvViewFixedAgentCommisionConfiguration.DataBind();
AgentCommissionType = AgentCommisionConfiguration.Rows[0]["CommissionDescription"].ToString();
ViewState["ViewAgentCommission"] = AgentCommisionConfiguration;
}
} catch (Exception Ex) {
_clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}
private void SetPreviousAgentCommission() {
try {
int rowIndex = 0;
if (ViewState["ViewAgentCommission"] != null) {
DataTable dt = (DataTable) ViewState["ViewAgentCommission"];
if (dt.Rows.Count > 0) {
for (int i = 0; i < dt.Rows.Count; i++) {
Label RowNumber = (Label) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[1].FindControl("RowNumber");
TextBox txtFixedAmountTabMinCount = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[1].FindControl("txtFixedAmountTabMinCount");
TextBox txtMaxCount = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[2].FindControl("txtMaxCount");
DropDownList ddlCommissionType = (DropDownList) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[3].FindControl("ddlCommissionType");
TextBox txtInterest = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[4].FindControl("txtInterest");
TextBox txtFixedAmount = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[5].FindControl("txtFixedAmount");
RowNumber.Text = Convert.ToString(rowIndex + 1);
txtFixedAmountTabMinCount.Text = dt.Rows[i]["MinCount"].ToString();
txtMaxCount.Text = dt.Rows[i]["MaxCount"].ToString();
ddlCommissionType.SelectedValue = dt.Rows[i]["CommissionType"].ToString();
txtInterest.Text = dt.Rows[i]["AgentWiseCommission"].ToString();
txtFixedAmount.Text = dt.Rows[i]["FixedAmount"].ToString();
rowIndex++;
}
}
}
} catch (Exception Ex) {
_clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}
protected void grvViewFixedAgentCommisionConfiguration_RowCommand(object sender, GridViewCommandEventArgs e) {
try {
string _CommandName = Convert.ToString(e.CommandName);
if (_CommandName == "AddCommssionDetails") {
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "Confirm()", true);
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes") {
// if (DateTime.Now.ToString("dd") == new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("dd"))
if (DateTime.Now.ToString("dd") == Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"])) {
int rowindex = 0;
if (ViewState["ViewAgentCommission"] != null) {
DataTable dtAgentComission = (DataTable) ViewState["ViewAgentCommission"];
DataRow drCurrentRow = null;
if (grvViewFixedAgentCommisionConfiguration.Rows.Count > 0) {
for (int i = 1; i <= grvViewFixedAgentCommisionConfiguration.Rows.Count; i++) {
Label RowNumber = (Label) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[1].FindControl("RowNumber");
TextBox txtFixedAmountTabMinCount = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[1].FindControl("txtFixedAmountTabMinCount");
TextBox txtMaxCount = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[2].FindControl("txtMaxCount");
DropDownList ddlCommissionType = (DropDownList) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[3].FindControl("ddlCommissionType");
TextBox txtInterest = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[4].FindControl("txtInterest");
TextBox txtFixedAmount = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[5].FindControl("txtFixedAmount");
Label lblCommissionType = (Label) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[6].FindControl("lblCommissionType");
Label lblCommissionTypeName = (Label) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[7].FindControl("lblCommissionTypeName");
drCurrentRow = dtAgentComission.NewRow();
drCurrentRow["RowNumber"] = i + 1;
dtAgentComission.Rows[i - 1]["MinCount"] = txtFixedAmountTabMinCount.Text;
dtAgentComission.Rows[i - 1]["MaxCount"] = txtMaxCount.Text;
dtAgentComission.Rows[i - 1]["CommissionType"] = ddlCommissionType.SelectedValue.ToString();
dtAgentComission.Rows[i - 1]["AgentWiseCommission"] = txtInterest.Text;
dtAgentComission.Rows[i - 1]["FixedAmount"] = txtFixedAmount.Text;
dtAgentComission.Rows[i - 1]["CommissionType"] = lblCommissionType.Text;
dtAgentComission.Rows[i - 1]["CommissionDescription"] = lblCommissionTypeName.Text;
rowindex++;
}
dtAgentComission.Rows.Add(drCurrentRow);
ViewState["ViewAgentCommission"] = dtAgentComission;
grvViewFixedAgentCommisionConfiguration.DataSource = dtAgentComission;
grvViewFixedAgentCommisionConfiguration.DataBind();
}
SetPreviousAgentCommission();
}
} else {
string DateValue = Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"]);
Response.Write("<script language='javascript'>window.alert('Commission slab can be change only on " + DateValue + " Date of month. " + "');</script>");
}
} else {
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "alert", string.Format("alert('You clicked Cancel.')"), true);
}
}
if (_CommandName == "RemoveAgentCommission") {
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "ConfirmOnCancel()", true);
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes") {
DataTable dtRemoveAgentComission = (DataTable) ViewState["ViewAgentCommission"];
DataRow drCurrentRow = null;
LinkButton lnkBtn = (LinkButton) e.CommandSource;
GridViewRow myRow = (GridViewRow) lnkBtn.Parent.Parent;
int rowindex = myRow.RowIndex;
hdfremovecommIDs.Value = rowindex.ToString();
int rowIndex1 = 0;
if (dtRemoveAgentComission.Rows.Count > 1) {
for (int i = 1; i <= grvViewFixedAgentCommisionConfiguration.Rows.Count; i++) {
Label RowNumber = (Label) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[1].FindControl("RowNumber");
TextBox txtFixedAmountTabMinCount = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[1].FindControl("txtFixedAmountTabMinCount");
TextBox txtMaxCount = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[2].FindControl("txtMaxCount");
DropDownList ddlCommissionType = (DropDownList) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[3].FindControl("ddlCommissionType");
TextBox txtInterest = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[4].FindControl("txtInterest");
TextBox txtFixedAmount = (TextBox) grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[5].FindControl("txtFixedAmount");
Label lblCommissionType = (Label) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[6].FindControl("lblCommissionType");
Label lblCommissionTypeName = (Label) grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[7].FindControl("lblCommissionTypeName");
drCurrentRow = dtRemoveAgentComission.NewRow();
dtRemoveAgentComission.Rows[i - 1]["MinCount"] = txtFixedAmountTabMinCount.Text;
dtRemoveAgentComission.Rows[i - 1]["MaxCount"] = txtMaxCount.Text;
dtRemoveAgentComission.Rows[i - 1]["CommissionType"] = ddlCommissionType.SelectedValue.ToString();
dtRemoveAgentComission.Rows[i - 1]["AgentWiseCommission"] = txtInterest.Text;
dtRemoveAgentComission.Rows[i - 1]["FixedAmount"] = txtFixedAmount.Text;
dtRemoveAgentComission.Rows[i - 1]["CommissionType"] = lblCommissionType.Text;
dtRemoveAgentComission.Rows[i - 1]["CommissionDescription"] = lblCommissionTypeName.Text;
rowIndex1++;
}
// dtRemoveAgentComission.Rows.Add(drCurrentRow);
dtRemoveAgentComission.Rows.Remove(dtRemoveAgentComission.Rows[rowindex]);
ViewState["VW_gvAgentcommission"] = dtRemoveAgentComission;
//RowsCountFromGV = dtRemoveAgentComission.Rows.Count;
// RowIndexFromGV = dtRemoveAgentComission.Rows.Count;
grvViewFixedAgentCommisionConfiguration.DataSource = dtRemoveAgentComission;
grvViewFixedAgentCommisionConfiguration.DataBind();
}
} else {
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "alert", string.Format("alert('You clicked Cancel.')"), true);
}
}
} catch (Exception Ex) {
_clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}
ASPX design shown below:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:GridView ID="grvViewFixedAgentCommisionConfiguration" runat="server" DataKeyNames="RowNumber" EmptyDataText="No Data Found" ShowFooter="true" class="display table-responsive" Style="border: 1px solid rgb(221, 221, 221); width: 100%;" CellPadding="0" CellSpacing="0" border="0" EnableModelValidation="True" OnRowDataBound="grvViewFixedAgentCommisionConfiguration_RowDataBound" AutoGenerateColumns="false" OnRowCommand="grvViewFixedAgentCommisionConfiguration_RowCommand">
<%--OnRowCreated="grvViewFixedAgentCommisionConfiguration_RowCreated"--%>
<Columns>
<asp:TemplateField HeaderText="Sl.No.">
<ItemTemplate>
<asp:Label ID="RowNumber" CssClass="control-label" runat="server" Text='<%#Container.DataItemIndex+1%>'></asp:Label>
</ItemTemplate>
<ItemStyle Wrap="false" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Min Count">
<ItemTemplate>
<asp:TextBox ID="txtFixedAmountTabMinCount" runat="server" MaxLength="33" PlaceHolder="Enter Minimum Count" CssClass="form-control" Width="100%" Text='<%#Eval("MinCount") %>'></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="txtInterest_FilteredtxtFixedAmountTabMinCount" runat="server" Enabled="True" TargetControlID="txtFixedAmountTabMinCount" FilterType="Numbers,Custom" FilterMode="ValidChars" ValidChars=" .">
</cc1:FilteredTextBoxExtender>
</ItemTemplate>
<ItemStyle Wrap="false" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Max Count">
<ItemTemplate>
<asp:TextBox ID="txtMaxCount" MaxLength="13" PlaceHolder="Enter Maximum Count" runat="server" CssClass="form-control" Text='<%#Eval("MaxCount") %>'></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="txtInterest_FilteredtxtMaxCount" runat="server" Enabled="True" TargetControlID="txtMaxCount" FilterType="Numbers,Custom" FilterMode="ValidChars" ValidChars=" .">
</cc1:FilteredTextBoxExtender>
</ItemTemplate>
<ItemStyle Wrap="false" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Commssion Type" Visible="false">
<ItemTemplate>
<asp:Label ID="lblcommissiontypeID" runat="server" Text='<%#Eval("CommissionType") %>' Visible="false"></asp:Label>
<asp:DropDownList ID="ddlCommissionType" runat="server" CssClass="form-control" OnSelectedIndexChanged="ddlCommissionType_SelectedIndexChanged" Width="100%" AutoPostBack="true">
<asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
<asp:ListItem Value="1" Text="Fixed Amount"> </asp:ListItem>
<asp:ListItem Value="2" Text="Percentage Wise"> </asp:ListItem>
</asp:DropDownList>
</div>
</ItemTemplate>
<ItemStyle Wrap="false" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Interest">
<ItemTemplate>
<asp:TextBox ID="txtInterest" MaxLength="13" PlaceHolder="Enter Interest Rate" runat="server" CssClass="form-control" Text='<%#Eval("AgentWiseCommission") %>'></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="txtInterest_FilteredTextBoxExtender" runat="server" Enabled="True" TargetControlID="txtInterest" FilterType="Numbers,Custom" FilterMode="ValidChars" ValidChars=" .">
</cc1:FilteredTextBoxExtender>
</ItemTemplate>
<ItemStyle Width="25%" Wrap="false" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Global Amount">
<ItemTemplate>
<asp:TextBox ID="txtFixedAmount" MaxLength="13" PlaceHolder="Enter Fixed Amount" runat="server" CssClass="form-control" Width="94%" Text='<%#Eval("FixedAmount") %>'></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="txtInterest_FilteredtxtFixedAmount" runat="server" Enabled="True" TargetControlID="txtFixedAmount" FilterType="Numbers,Custom" FilterMode="ValidChars" ValidChars=" .">
</cc1:FilteredTextBoxExtender>
</ItemTemplate>
<ItemStyle Width="25%" Wrap="false" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Commision Type" Visible="false">
<ItemTemplate>
<asp:Label ID="lblCommissionType" runat="server" Text='<%#Eval("CommissionType")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Commision Type Name" Visible="false">
<ItemTemplate>
<asp:Label ID="lblCommissionTypeName" runat="server" Text='<%#Eval("CommissionDescription")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:LinkButton ID="btnRemoveAgentCommission" runat="server" CommandName="RemoveAgentCommission" OnClientClick="ConfirmOnCancel()" CommandArgument='<%#Eval("RowNumber") %>' Visible="false">
<asp:Image ImageUrl="../Images/minus.png" ID="imgRemoveTeamEmployee" runat="server" ToolTip="Click to delete this row" Style="cursor: pointer;" rel="tooltip" data-original-title="RemoveTeamEmployeeSubTask" class="tableActionButton" />
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="4%" Wrap="false" />
<FooterTemplate>
<asp:LinkButton ID="btnAddSubTask" runat="server" CommandName="AddCommssionDetails" OnClientClick="Confirm()" CommandArgument='<%#Eval("RowNumber") %>'>
<asp:Image ImageUrl="../Images/plus.png" ID="imgAddEmp" runat="server" ToolTip="Click to add new Row" Style="cursor: pointer;" rel="tooltip" data-original-title="AddSubTask" class="tableActionButton" />
</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Content>
ClassFiles.clsCommandFunctions _clsCommandFunctions = new ClassFiles.clsCommandFunctions();
DataTable GetCommissionAgent = null;
string AgentCode = string.Empty;
string CommisionType = string.Empty;
string ViewCommisionType = string.Empty;
string CommisionMinCount1 = string.Empty;
string CommisionMaxCount1 = string.Empty;
string CommisionAmount1 = string.Empty;
string CommisionPercentage1 = string.Empty;
string CommisionMinCount2 = string.Empty;
string CommisionMaxCount2 = string.Empty;
string CommisionAmount2 = string.Empty;
string CommisionPercentage2 = string.Empty;
string CommisionMinCount3 = string.Empty;
string CommisionMaxCount3 = string.Empty;
string CommisionAmount3 = string.Empty;
string CommisionPercentage3 = string.Empty;
DataTable InsertOrUpdateAgentCommission = null;
DataTable FixedUpdateAgentCommission = null;
DataTable RemoveAgentWiseCommission = null;
DataSet ViewAgentCommissionData = new DataSet();
string NewAgentcode = string.Empty;
string ViewAgentCode = string.Empty;
string EditAgentCode = string.Empty;
string Type = string.Empty;
int Status = -1;
// start of Initialization of variable for maintaining adding and removing row index
int RowsCountFromGV = 0;
int RowIndexFromGV = -1;
// End of Initialization of variable for maintaining adding and removing row index
DataTable GetViewCommissionDetails = null;
DataSet ViewAgentData = new DataSet();
DataTable InsertUpdateAgentCommission = null;
string CommissionDescription = string.Empty;
if (!IsPostBack)
{
if (Session["Username"] != null)
{
LoadGrid();
fillAgentCommisionData();
}
else
{
Response.Redirect("~/frmLogin.aspx");
}
}
enter code here
public void LoadGrid()
{
try
{
DataTable DtLoadAgentCommission = new DataTable();
DtLoadAgentCommission.Columns.Add("RowNumber");
DtLoadAgentCommission.Columns.Add("MinCount");
DtLoadAgentCommission.Columns.Add("MaxCount");
DtLoadAgentCommission.Columns.Add("AgentWiseCommission");
DtLoadAgentCommission.Columns.Add("FixedAmount");
DtLoadAgentCommission.Columns.Add("CommissionType");
DtLoadAgentCommission.Columns.Add("CommissionDescription");
DataRow dr = DtLoadAgentCommission.NewRow();
dr["RowNumber"] = "1";
dr["MinCount"] = string.Empty;
dr["MaxCount"] = string.Empty;
dr["CommissionType"] = string.Empty;
dr["AgentWiseCommission"] = string.Empty;
dr["FixedAmount"] = string.Empty;
dr["CommissionDescription"] = string.Empty;
DtLoadAgentCommission.Rows.Add(dr);
grvViewFixedAgentCommisionConfiguration.DataSource = DtLoadAgentCommission;
grvViewFixedAgentCommisionConfiguration.DataBind();
ViewState["ViewAgentCommission"] = DtLoadAgentCommission;
}
catch (Exception Ex)
{
_clsCommandFunctions.writeLog("Exception Occurred :\n ." + Ex.Message);
}
}
enter code here
public void fillAgentCommisionData()
{
try
{
DataTable AgentCommisionConfiguration = new DataTable();
AgentCommisionConfiguration = MobilePortalProcess.GetAgentCommisionConfigurationDetails();
RowsCountFromGV = AgentCommisionConfiguration.Rows.Count; // To store total count of records for showing remove row option
if (AgentCommisionConfiguration.Rows.Count > 0)
{
if (rbtnFixedAmountTab1.SelectedValue.Equals("0") || rbtnFixedAmountTab1.SelectedValue.Equals("1") || rbtnFixedAmountTab1.SelectedValue.Equals("2"))
{
LoadGrid();
hdfremovecommIDs.Value = string.Empty;
HiddenFieldForChange.Value = string.Empty;
}
else
{
rbtnFixedAmountTab1.Items.FindByText(AgentCommisionConfiguration.Rows[0]["CommissionDescription"].ToString()).Selected = true;
}
grvViewFixedAgentCommisionConfiguration.DataSource = AgentCommisionConfiguration;
grvViewFixedAgentCommisionConfiguration.DataBind();
AgentCommissionType = AgentCommisionConfiguration.Rows[0]["CommissionDescription"].ToString();
ViewState["ViewAgentCommission"] = AgentCommisionConfiguration;
}
}
catch (Exception Ex)
{
_clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}
enter code here
protected void rbtnFixedAmountTab1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (DateTime.Now.ToString("dd") == Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"]))
{
fillAgentCommisionData();
if (rbtnFixedAmountTab1.SelectedIndex == 0)
{
grvViewFixedAgentCommisionConfiguration.Columns[4].Visible = false;
grvViewFixedAgentCommisionConfiguration.Columns[5].Visible = true;
}
else if (rbtnFixedAmountTab1.SelectedIndex == 1)
{
grvViewFixedAgentCommisionConfiguration.Columns[4].Visible = true;
grvViewFixedAgentCommisionConfiguration.Columns[5].Visible = false;
}
}
else
{
if (rbtnFixedAmountTab1.SelectedIndex == 1)
{
rbtnFixedAmountTab1.SelectedValue = "1";
}
else
{
rbtnFixedAmountTab1.SelectedValue = "2";
}
string DateValue = Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"]);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "InvalidArgs", "alert('Commission type can be change only on " + DateValue + " Date of month.');", true);
}
}
ModalPopupBranchWiseTotalAllocatedPopup.Show();
}
catch (Exception ex)
{
AppLog.ErrorLog(sender, ex);
ScriptManager.RegisterStartupScript(this.Page, typeof(string), "msg", "alert('Alarm: Contact system administrator');", true);
}
}
protected void grvViewFixedAgentCommisionConfiguration_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RowIndexFromGV = Convert.ToInt32(RowIndexFromGV + 1); // For storing Initial index of gridId
TextBox txtFixedAmountTabMinCount = (TextBox)e.Row.FindControl("txtFixedAmountTabMinCount");
TextBox txtMaxCount = (TextBox)e.Row.FindControl("txtMaxCount");
DropDownList ddlCommissionType = (DropDownList)e.Row.FindControl("ddlCommissionType");
TextBox txtInterest = (TextBox)e.Row.FindControl("txtInterest");
TextBox txtFixedAmount = (TextBox)e.Row.FindControl("txtFixedAmount");
Label lblcommissiontypeID = (Label)e.Row.FindControl("lblcommissiontypeID");
LinkButton btnRemoveAgentCommission = (LinkButton)e.Row.FindControl("btnRemoveAgentCommission");
DataTable AgentCommisionConfiguration = new DataTable();
AgentCommisionConfiguration = MobilePortalProcess.GetEditedAgentWiseCommisionDetails(AgentCode);
RowsCountFromGV = AgentCommisionConfiguration.Rows.Count;
string checkpostrowindex = e.Row.RowIndex.ToString();
if (!string.IsNullOrEmpty(hdfremovecommIDs.Value))
{
// This used for storing Index of after removing new row
int removedId = Convert.ToInt32(hdfremovecommIDs.Value) - 1;
if (removedId.ToString().Equals(checkpostrowindex))
{
btnRemoveAgentCommission.Visible = true;
}
}
else if (!string.IsNullOrEmpty(HiddenFieldForChange.Value))
{
int ViewAddedRow = Convert.ToInt32(HiddenFieldForChange.Value) - 1;
if (ViewAddedRow.ToString().Equals(checkpostrowindex))
{
btnRemoveAgentCommission.Visible = true;
}
}
else
if (RowsCountFromGV == RowIndexFromGV)
{
//For checking rowcount of gridview from pageload and after selected index change of radio button
btnRemoveAgentCommission.Visible = true;
}
if (rbtnFixedAmountTab1.SelectedValue == "1")
{
grvViewFixedAgentCommisionConfiguration.Columns[4].Visible = false;
grvViewFixedAgentCommisionConfiguration.Columns[5].Visible = true;
}
else
{
grvViewFixedAgentCommisionConfiguration.Columns[4].Visible = true;
grvViewFixedAgentCommisionConfiguration.Columns[5].Visible = false;
}
}
ModalPopupBranchWiseTotalAllocatedPopup.Show();
}
catch (Exception Ex)
{
_clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}
private void SetPreviousAgentCommission()
{
try
{
int rowIndex = 0;
if (ViewState["ViewAgentCommission"] != null)
{
DataTable dt = (DataTable)ViewState["ViewAgentCommission"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Label RowNumber = (Label)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[1].FindControl("RowNumber");
TextBox txtFixedAmountTabMinCount = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[1].FindControl("txtFixedAmountTabMinCount");
TextBox txtMaxCount = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[2].FindControl("txtMaxCount");
DropDownList ddlCommissionType = (DropDownList)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[3].FindControl("ddlCommissionType");
TextBox txtInterest = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[4].FindControl("txtInterest");
TextBox txtFixedAmount = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex].Cells[5].FindControl("txtFixedAmount");
RowNumber.Text = Convert.ToString(rowIndex + 1);
txtFixedAmountTabMinCount.Text = dt.Rows[i]["MinCount"].ToString();
txtMaxCount.Text = dt.Rows[i]["MaxCount"].ToString();
ddlCommissionType.SelectedValue = dt.Rows[i]["CommissionType"].ToString();
txtInterest.Text = dt.Rows[i]["AgentWiseCommission"].ToString();
txtFixedAmount.Text = dt.Rows[i]["FixedAmount"].ToString();
rowIndex++;
}
}
}
}
catch (Exception Ex)
{
_clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}
protected void grvViewFixedAgentCommisionConfiguration_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
string _CommandName = Convert.ToString(e.CommandName);
if (_CommandName == "AddCommssionDetails")
{
if (confirmValue.Value.ToString().Trim().Equals("Yes"))
{
if (DateTime.Now.ToString("dd") == Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"]))
{
int rowindex = 0;
if (ViewState["ViewAgentCommission"] != null)
{
DataTable dtAgentComission = (DataTable)ViewState["ViewAgentCommission"];
DataRow drCurrentRow = null;
if (grvViewFixedAgentCommisionConfiguration.Rows.Count > 0)
{
int rowindex2 = grvViewFixedAgentCommisionConfiguration.Rows.Count - 1;
for (int i = 1; i <= grvViewFixedAgentCommisionConfiguration.Rows.Count; i++)
{
Label RowNumber = (Label)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[1].FindControl("RowNumber");
TextBox txtFixedAmountTabMinCount = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[1].FindControl("txtFixedAmountTabMinCount");
TextBox txtMaxCount = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[2].FindControl("txtMaxCount");
DropDownList ddlCommissionType = (DropDownList)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[3].FindControl("ddlCommissionType");
TextBox txtInterest = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[4].FindControl("txtInterest");
TextBox txtFixedAmount = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[5].FindControl("txtFixedAmount");
Label lblCommissionType = (Label)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[6].FindControl("lblCommissionType");
Label lblCommissionTypeName = (Label)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[7].FindControl("lblCommissionTypeName");
drCurrentRow = dtAgentComission.NewRow();
drCurrentRow["RowNumber"] = i + 1;
dtAgentComission.Rows[i - 1]["MinCount"] = txtFixedAmountTabMinCount.Text;
dtAgentComission.Rows[i - 1]["MaxCount"] = txtMaxCount.Text;
dtAgentComission.Rows[i - 1]["CommissionType"] = ddlCommissionType.SelectedValue.ToString();
dtAgentComission.Rows[i - 1]["AgentWiseCommission"] = txtInterest.Text;
dtAgentComission.Rows[i - 1]["FixedAmount"] = txtFixedAmount.Text;
dtAgentComission.Rows[i - 1]["CommissionType"] = lblCommissionType.Text;
dtAgentComission.Rows[i - 1]["CommissionDescription"] = lblCommissionTypeName.Text;
rowindex++;
}
if ((dtAgentComission.Rows[rowindex2]["MinCount"] != "") && (dtAgentComission.Rows[rowindex2]["MaxCount"] != "") && ((dtAgentComission.Rows[rowindex2]["AgentWiseCommission"] != "") || (dtAgentComission.Rows[rowindex2]["FixedAmount"] != "")) || (dtAgentComission.Rows[rowindex2]["CommissionType"] != ""))
{
dtAgentComission.Rows.Add(drCurrentRow);
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Kindly filled records and click on save button first to add new row.');", true);
}
ViewState["ViewAgentCommission"] = dtAgentComission;
//start of region for hidden field for storing row id value
int CurrentTotalRowCount = dtAgentComission.Rows.Count;
HiddenFieldForChange.Value = CurrentTotalRowCount.ToString();
//End of region for hidden field for storing row id value grvViewFixedAgentCommisionConfiguration.DataSource = dtAgentComission;
grvViewFixedAgentCommisionConfiguration.DataBind();
}
SetPreviousAgentCommission();
}
}
else
{
string DateValue = Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"]);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "InvalidArgs", "alert('Commission type can be change only on " + DateValue + " Date of month.');", true);
}
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('You clicked Cancel.');", true);
}
ModalPopupBranchWiseTotalAllocatedPopup.Show();
}
if (_CommandName == "RemoveAgentCommission")
{
if (confirmValue.Value.ToString().Trim().Equals("Yes"))
{
if (DateTime.Now.ToString("dd") == Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"]))
{
DataTable dtRemoveAgentComission = (DataTable)ViewState["ViewAgentCommission"];
DataRow drCurrentRow = null;
LinkButton lnkBtn = (LinkButton)e.CommandSource;
GridViewRow myRow = (GridViewRow)lnkBtn.Parent.Parent;
int rowindex = myRow.RowIndex;
hdfremovecommIDs.Value = rowindex.ToString(); // For storing latest index of row for showing row removal option to the latest row.
int rowIndex1 = 0;
if (dtRemoveAgentComission.Rows.Count > 1)
{
for (int i = 1; i <= grvViewFixedAgentCommisionConfiguration.Rows.Count; i++)
{
Label RowNumber = (Label)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[1].FindControl("RowNumber");
TextBox txtFixedAmountTabMinCount = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[1].FindControl("txtFixedAmountTabMinCount");
TextBox txtMaxCount = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[2].FindControl("txtMaxCount");
DropDownList ddlCommissionType = (DropDownList)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[3].FindControl("ddlCommissionType");
TextBox txtInterest = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[4].FindControl("txtInterest");
TextBox txtFixedAmount = (TextBox)grvViewFixedAgentCommisionConfiguration.Rows[rowIndex1].Cells[5].FindControl("txtFixedAmount");
Label lblCommissionType = (Label)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[6].FindControl("lblCommissionType");
Label lblCommissionTypeName = (Label)grvViewFixedAgentCommisionConfiguration.Rows[rowindex].Cells[7].FindControl("lblCommissionTypeName");
drCurrentRow = dtRemoveAgentComission.NewRow();
dtRemoveAgentComission.Rows[i - 1]["MinCount"] = txtFixedAmountTabMinCount.Text;
dtRemoveAgentComission.Rows[i - 1]["MaxCount"] = txtMaxCount.Text;
dtRemoveAgentComission.Rows[i - 1]["CommissionType"] = ddlCommissionType.SelectedValue.ToString();
dtRemoveAgentComission.Rows[i - 1]["AgentWiseCommission"] = txtInterest.Text;
dtRemoveAgentComission.Rows[i - 1]["FixedAmount"] = txtFixedAmount.Text;
dtRemoveAgentComission.Rows[i - 1]["CommissionType"] = lblCommissionType.Text;
dtRemoveAgentComission.Rows[i - 1]["CommissionDescription"] = lblCommissionTypeName.Text;
rowIndex1++;
} dtRemoveAgentComission.Rows.Remove(dtRemoveAgentComission.Rows[rowindex]);
ViewState["VW_gvAgentcommission"] = dtRemoveAgentComission;
grvViewFixedAgentCommisionConfiguration.DataSource = dtRemoveAgentComission;
grvViewFixedAgentCommisionConfiguration.DataBind();
AgentCode = lblAgentCode.Text;
ViewAgentCommissionData = MobilePortalProcess.ViewEditAgentRangeWiseCommissionData(rowIndex1, AgentCode);
if (grvViewFixedAgentCommisionConfiguration.Rows.Count > 0)
{
if (ViewAgentCommissionData.Tables[0] != null)
{
if (ViewAgentCommissionData.Tables[0].Rows.Count > 0)
{
string AgentCodeData = string.Empty;
string MiCount = string.Empty;
string MaxCount = string.Empty;
string CommissionType = string.Empty;
string CommissionDescription = string.Empty; MiCount = ViewAgentCommissionData.Tables[0].Rows[0]["MinCount"].ToString();
MaxCount = ViewAgentCommissionData.Tables[0].Rows[0]["MaxCount"].ToString();
string FixedAmount = ViewAgentCommissionData.Tables[0].Rows[0]["FixedAmount"].ToString() == "" ? string.Empty : ViewAgentCommissionData.Tables[0].Rows[0]["FixedAmount"].ToString();
string AgentWiseCommission = ViewAgentCommissionData.Tables[0].Rows[0]["AgentWiseCommission"].ToString() == "" ? string.Empty : ViewAgentCommissionData.Tables[0].Rows[0]["AgentWiseCommission"].ToString();
CommissionDescription = ViewAgentCommissionData.Tables[0].Rows[0]["CommissionDescription"].ToString(); RemoveEditAgentWiseIndividualCommission(
Convert.ToString(rowIndex1),
MiCount, MaxCount, CommissionType, CommissionDescription, FixedAmount, AgentWiseCommission,
Convert.ToString(Session["Username"]), AgentCode);
}
}
}
}
}
else
{
string DateValue = Convert.ToString(ConfigurationManager.AppSettings["StartOfDate"]);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "InvalidArgs", "alert('Commission type can be change only on " + DateValue + " Date of month.');", true);
}
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('You clicked Cancel.');", true);
}
ModalPopupBranchWiseTotalAllocatedPopup.Show();
}
}
catch (Exception Ex)
{
_clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}
private void RemoveEditAgentWiseIndividualCommission(string RowIndex, string MinCount, string MaxCount, string CommissionTypeID, string CommissionDescription, string FixedAmount, string PercentageInterest, string CreatedBy, string AgentCodeData)
{
try
{
RemoveAgentWiseCommission = MobilePortalProcess.RemoveEditAgentWiseIndividualCommission(RowIndex, MinCount, MaxCount, CommissionTypeID, CommissionDescription, FixedAmount, PercentageInterest, CreatedBy, AgentCodeData);
if (RemoveAgentWiseCommission.Rows.Count > 0)
{
ScriptManager.RegisterStartupScript(this.Page, typeof(string), "msg", "alert('AgentWise Commission Slab Removed Successfully.');window.location='../AgencyBanking/AgentEditCommissionConfiguration.aspx';", true);
}
else
{
ScriptManager.RegisterStartupScript(this.Page, typeof(string), "msg", "alert('Contact system administrator.');window.location='../AgencyBanking/AgentEditCommissionConfiguration.aspx';", true);
}
}
catch (Exception Ex)
{ _clsCommandFunctions.writeLog("Exception Occured :\n ." + Ex.Message);
}
}

determine button click and modify values in another button aspx.net

I have dynamically created Data Table bind to Grid View. In every row I'm adding button which i'm define in grid view. Now I want that button to call in another button click event and make modifications in values.Is that possible?Here is my code:
<asp:GridView ID="GridView2" runat="server" OnRowDataBound="GridView2_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnTest" runat="server" CommandName="odzemi" CssClass="button2" OnClick="btnTest_Click" Text="-" Width="100px" Font-Bold="True" />
<asp:Button ID="Button15" Visible="false" runat="server" Text="Button" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void btnTest_Click(object sender, EventArgs e)
{
Session["Counter1"] = newValue;
Session["Counter"] = newValue;
if (Session["Markici"] != null || Session["Markici"] != null)
{
var clickedRow = ((Button)sender).NamingContainer as GridViewRow;
var clickedIndex = clickedRow.RowIndex;
/*decimal*/ old = dtCurrentTable.Rows[clickedIndex].Field<decimal>("Kolicina");
decimal oldIznos = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkIznos");
decimal VkDanok = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkDanok");
string Cena1 = dtCurrentTable.Rows[clickedIndex].Field<string>("Cena1");
int TarifaID = dtCurrentTable.Rows[clickedIndex].Field<Int16>("TarifaID");
// decimal pocentDanok0 = 0.0m;
// decimal pocentDanok1 = 0.18m;
// decimal pocentDanok2 = 0.5m;
//int oldValue = int.Parse(old);
/* decimal*/ newValue = old - 1; //
Label37.Text = newValue.ToString();
decimal newIznos = oldIznos - Convert.ToDecimal(Cena1);
dtCurrentTable.Rows[clickedIndex].SetField("Kolicina", newValue.ToString());
dtCurrentTable.Rows[clickedIndex].SetField("VkIznos", newIznos.ToString());
}
//I want here to call btn_test click and modyfy his values
protected void Button7_Click(object sender, EventArgs e)
{
if (GridView2.Rows.Count == 0)
{
Response.Redirect("MasiGradskaKafanak1.aspx");
}
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["string2"].ConnectionString);
Session["Counter"] = counter;
Label11.Text = counter.ToString();
// Label11.Text = Session["kolicina2"].ToString(); //ViewState["count"].ToString(); //
if (reader.Read())
{
Label35.Text = (string)reader["pkid"].ToString();
Label12.Text = (string)reader["Artikal"].ToString();
Label33.Text = (string)reader["Vid"].ToString();
Label34.Text = (string)reader["EdMera"].ToString();
Label14.Text = (string)reader["TarifaID"].ToString();
Label13.Text = (string)reader["Cena1"].ToString();
//iznos
decimal mnoz = Convert.ToDecimal(Label11.Text) * Convert.ToDecimal(Label13.Text);
Label17.Text = mnoz.ToString();
decimal.Parse(Label17.Text);
decimal cena;
cena = Convert.ToDecimal(Label13.Text);
decimal kolicina;
kolicina = Convert.ToDecimal(Label11.Text);
decimal iznos;
iznos = Convert.ToDecimal(Label17.Text);
Session["cena1"] = Label13.Text;
Session["iznos1"] = Label17.Text;
if (Label14.Text == "0")
{
decimal pocentDanok = 0.0m;
vkdanok1 = Convert.ToDecimal(vkdanok1) + Convert.ToDecimal(cena) * Convert.ToDecimal(kolicina) * Convert.ToDecimal(pocentDanok) / (1 + Convert.ToDecimal(pocentDanok));
vkdanok1 = Math.Truncate(vkdanok1 * 10000m) / 10000m;
Label18.Text = vkdanok.ToString();//vkdanok
}
else if (Label14.Text == "1")
{
decimal pocentDanok = 0.18m;
vkdanok1 = (vkdanok1) + Convert.ToDecimal(cena) * Convert.ToDecimal(kolicina) * Convert.ToDecimal(pocentDanok) / (1 + Convert.ToDecimal(pocentDanok));
vkdanok1 = Math.Truncate(vkdanok1 * 10000m) / 10000m;
Label18.Text = vkdanok1.ToString();//VkDanok
}
else if (Label14.Text == "2")
{
decimal pocentDanok = 0.5m;
vkdanok1 = Convert.ToDecimal(vkdanok1) + Convert.ToDecimal(cena) * Convert.ToDecimal(kolicina) * Convert.ToDecimal(pocentDanok) / (1 + Convert.ToDecimal(pocentDanok));
vkdanok1 = Math.Truncate(vkdanok1 * 10000m) / 10000m;
Label18.Text = vkdanok1.ToString();//vkdanok
}
conn.Close();
}
DataTable dtCurrentTable = (DataTable)ViewState["Markici"];
if (Label37.Text == "0")
{
dtCurrentTable.Rows[0]["Kolicina"] = Label11.Text;
}
else if (Label37.Text != "0")
{
Counter1 = Counter1 + 1;
dtCurrentTable.Rows[0]["Kolicina"] = Convert.ToInt32(Label37.Text) + Counter1;// Label37.Text;//Convert.ToInt32(Label37.Text) + 3;
}
dtCurrentTable.Rows[0]["Artikal"] = Label12.Text;
dtCurrentTable.Rows[0]["Cena1"] = Label13.Text;
dtCurrentTable.Rows[0]["VkIznos"] = Label17.Text;
dtCurrentTable.Rows[0]["VkDanok"] = Label18.Text;
dtCurrentTable.Rows[0]["EdMera"] = Label34.Text;
dtCurrentTable.Rows[0]["ArtikalID"] = Label35.Text;
dtCurrentTable.Rows[0]["Vid"] = Label33.Text;
dtCurrentTable.Rows[0]["TarifaID"] = Label14.Text;
dtCurrentTable.AcceptChanges();
GridView2.DataSource = dtCurrentTable;
GridView2.DataBind();
RemoveDuplicates(dt);
}
You can use the EditItemTemplate to corresponding every templatefield in gridview.

How to apply javascript on SelectedIndexChanging of grid view

I have wriiten a javascript which I am using it onblur event of textbox which is inside a gridview. The same script should fire for me when I perform SelectedIndexChanging of gridview. This is my script
<script type="text/javascript">
function total(txtQuantity, txtRate, txtAmount) {
var col1;
var totalcol1 = 0;
var weight = document.getElementById(txtQuantity).value;
var rate = document.getElementById(txtRate).value;
var tot = weight * rate;
document.getElementById(txtAmount).value = tot.toFixed(2).toString();
var grid = document.getElementById('<%=grdInvoice.ClientID %>');
for (i = 0; i < grid.rows.length; i++) {
col1 = grid.rows[i].cells[4];
//col2 = grid.rows[i].cells[1];
for (j = 0; j < col1.childNodes.length; j++) {
if (col1.childNodes[j].type == "text") {
if (!isNaN(col1.childNodes[j].value) && col1.childNodes[j].value != "") {
totalcol1 += parseInt(col1.childNodes[j].value)
}
}
}
}
document.getElementById('<%= lblTotal.ClientID %>').innerHTML = totalcol1.toFixed(2).toString();
document.getElementById('<%=lblResultbalance.ClientID%>').innerHTML = totalcol1.toFixed(2).toString();
document.getElementById('<%=TextBox1.ClientID%>').value = totalcol1.toFixed(2).toString();
}
Can some one help me
Try this in your event
ScriptManager.RegisterStartupScript(this, GetType(), "script", "total('" + txt1.ClientID + "','" + txt2.ClientID + "','" + txt3.ClientID + "')", true);

Fixed GridView Header with horizontal and vertical scrolling in asp.net

I want to fix(Freeze) gridview header while vertical scrolling.
I also want to fix first column while horizontal scrolling.
I want this in both chrome and IE.
It is possible to apply the specific GridView / Table layout via custom CSS rules (as it was discussed in the <table><tbody> scrollable? thread) to fix GridView's Header. However, this approach will not work in all browsers. The 3-rd ASP.NET GridView controls (such as the ASPxGridView from DevExpress component vendor provide this functionality.
Check also the following CodeProject solutions:
Fixed header Grid
Gridview with fixed header
Gridview Fixed Header
I was looking for a solution for this for a long time and found most of the answers are not working or not suitable for my situation i also find most of the java script code for that they worked but only with the vertical scroll not with the horizontal scroll and also combination of header and rows doesn't match.
Finally i have found a solution with javascript here is the link bellow :-
scrollable horizontal and vertical grid view with fixed headers
Refer Here which is 100% working
https://stackoverflow.com/a/59357398/11863405
Static Header for Gridview Control
You can try overflow css property.
// create this Js and add reference
var GridViewScrollOptions = /** #class */ (function () {
function GridViewScrollOptions() {
}
return GridViewScrollOptions;
}());
var GridViewScroll = /** #class */ (function ()
{
function GridViewScroll(options) {
this._initialized = false;
if (options.elementID == null)
options.elementID = "";
if (options.width == null)
options.width = "700";
if (options.height == null)
options.height = "350";
if (options.freezeColumnCssClass == null)
options.freezeColumnCssClass = "";
if (options.freezeFooterCssClass == null)
options.freezeFooterCssClass = "";
if (options.freezeHeaderRowCount == null)
options.freezeHeaderRowCount = 1;
if (options.freezeColumnCount == null)
options.freezeColumnCount = 1;
this.initializeOptions(options);
}
GridViewScroll.prototype.initializeOptions = function (options) {
this.GridID = options.elementID;
this.GridWidth = options.width;
this.GridHeight = options.height;
this.FreezeColumn = options.freezeColumn;
this.FreezeFooter = options.freezeFooter;
this.FreezeColumnCssClass = options.freezeColumnCssClass;
this.FreezeFooterCssClass = options.freezeFooterCssClass;
this.FreezeHeaderRowCount = options.freezeHeaderRowCount;
this.FreezeColumnCount = options.freezeColumnCount;
};
GridViewScroll.prototype.enhance = function ()
{
this.FreezeCellWidths = [];
this.IsVerticalScrollbarEnabled = false;
this.IsHorizontalScrollbarEnabled = false;
if (this.GridID == null || this.GridID == "")
{
return;
}
this.ContentGrid = document.getElementById(this.GridID);
if (this.ContentGrid == null) {
return;
}
if (this.ContentGrid.rows.length < 2) {
return;
}
if (this._initialized) {
this.undo();
}
this._initialized = true;
this.Parent = this.ContentGrid.parentNode;
this.ContentGrid.style.display = "none";
if (typeof this.GridWidth == 'string' && this.GridWidth.indexOf("%") > -1) {
var percentage = parseInt(this.GridWidth);
this.Width = this.Parent.offsetWidth * percentage / 100;
}
else {
this.Width = parseInt(this.GridWidth);
}
if (typeof this.GridHeight == 'string' && this.GridHeight.indexOf("%") > -1) {
var percentage = parseInt(this.GridHeight);
this.Height = this.Parent.offsetHeight * percentage / 100;
}
else {
this.Height = parseInt(this.GridHeight);
}
this.ContentGrid.style.display = "";
this.ContentGridHeaderRows = this.getGridHeaderRows();
this.ContentGridItemRow = this.ContentGrid.rows.item(this.FreezeHeaderRowCount);
var footerIndex = this.ContentGrid.rows.length - 1;
this.ContentGridFooterRow = this.ContentGrid.rows.item(footerIndex);
this.Content = document.createElement('div');
this.Content.id = this.GridID + "_Content";
this.Content.style.position = "relative";
this.Content = this.Parent.insertBefore(this.Content, this.ContentGrid);
this.ContentFixed = document.createElement('div');
this.ContentFixed.id = this.GridID + "_Content_Fixed";
this.ContentFixed.style.overflow = "auto";
this.ContentFixed = this.Content.appendChild(this.ContentFixed);
this.ContentGrid = this.ContentFixed.appendChild(this.ContentGrid);
this.ContentFixed.style.width = String(this.Width) + "px";
if (this.ContentGrid.offsetWidth > this.Width) {
this.IsHorizontalScrollbarEnabled = true;
}
if (this.ContentGrid.offsetHeight > this.Height) {
this.IsVerticalScrollbarEnabled = true;
}
this.Header = document.createElement('div');
this.Header.id = this.GridID + "_Header";
this.Header.style.backgroundColor = "#F0F0F0";
this.Header.style.position = "relative";
this.HeaderFixed = document.createElement('div');
this.HeaderFixed.id = this.GridID + "_Header_Fixed";
this.HeaderFixed.style.overflow = "hidden";
this.Header = this.Parent.insertBefore(this.Header, this.Content);
this.HeaderFixed = this.Header.appendChild(this.HeaderFixed);
this.ScrollbarWidth = this.getScrollbarWidth();
this.prepareHeader();
this.calculateHeader();
this.Header.style.width = String(this.Width) + "px";
if (this.IsVerticalScrollbarEnabled) {
this.HeaderFixed.style.width = String(this.Width - this.ScrollbarWidth) + "px";
if (this.IsHorizontalScrollbarEnabled) {
this.ContentFixed.style.width = this.HeaderFixed.style.width;
if (this.isRTL()) {
this.ContentFixed.style.paddingLeft = String(this.ScrollbarWidth) + "px";
}
else {
this.ContentFixed.style.paddingRight = String(this.ScrollbarWidth) + "px";
}
}
this.ContentFixed.style.height = String(this.Height - this.Header.offsetHeight) + "px";
}
else {
this.HeaderFixed.style.width = this.Header.style.width;
this.ContentFixed.style.width = this.Header.style.width;
}
if (this.FreezeColumn && this.IsHorizontalScrollbarEnabled) {
this.appendFreezeHeader();
this.appendFreezeContent();
}
if (this.FreezeFooter && this.IsVerticalScrollbarEnabled) {
this.appendFreezeFooter();
if (this.FreezeColumn && this.IsHorizontalScrollbarEnabled) {
this.appendFreezeFooterColumn();
}
}
var self = this;
this.ContentFixed.onscroll = function (event) {
self.HeaderFixed.scrollLeft = self.ContentFixed.scrollLeft;
if (self.ContentFreeze != null)
self.ContentFreeze.scrollTop = self.ContentFixed.scrollTop;
if (self.FooterFreeze != null)
self.FooterFreeze.scrollLeft = self.ContentFixed.scrollLeft;
};
};
GridViewScroll.prototype.getGridHeaderRows = function () {
var gridHeaderRows = new Array();
for (var i = 0; i < this.FreezeHeaderRowCount; i++) {
gridHeaderRows.push(this.ContentGrid.rows.item(i));
}
return gridHeaderRows;
};
GridViewScroll.prototype.prepareHeader = function () {
this.HeaderGrid = this.ContentGrid.cloneNode(false);
this.HeaderGrid.id = this.GridID + "_Header_Fixed_Grid";
this.HeaderGrid = this.HeaderFixed.appendChild(this.HeaderGrid);
this.prepareHeaderGridRows();
for (var i = 0; i < this.ContentGridItemRow.cells.length; i++) {
this.appendHelperElement(this.ContentGridItemRow.cells.item(i));
this.appendHelperElement(this.HeaderGridHeaderCells[i]);
}
};
GridViewScroll.prototype.prepareHeaderGridRows = function () {
this.HeaderGridHeaderRows = new Array();
for (var i = 0; i < this.FreezeHeaderRowCount; i++) {
var gridHeaderRow = this.ContentGridHeaderRows[i];
var headerGridHeaderRow = gridHeaderRow.cloneNode(true);
this.HeaderGridHeaderRows.push(headerGridHeaderRow);
this.HeaderGrid.appendChild(headerGridHeaderRow);
}
this.prepareHeaderGridCells();
};
GridViewScroll.prototype.prepareHeaderGridCells = function () {
this.HeaderGridHeaderCells = new Array();
for (var i = 0; i < this.ContentGridItemRow.cells.length; i++) {
for (var rowIndex in this.HeaderGridHeaderRows) {
var cgridHeaderRow = this.HeaderGridHeaderRows[rowIndex];
var fixedCellIndex = 0;
for (var cellIndex = 0; cellIndex < cgridHeaderRow.cells.length; cellIndex++) {
var cgridHeaderCell = cgridHeaderRow.cells.item(cellIndex);
if (cgridHeaderCell.colSpan == 1 && i == fixedCellIndex) {
this.HeaderGridHeaderCells.push(cgridHeaderCell);
}
else {
fixedCellIndex += cgridHeaderCell.colSpan - 1;
}
fixedCellIndex++;
}
}
}
};
GridViewScroll.prototype.calculateHeader = function () {
for (var i = 0; i < this.ContentGridItemRow.cells.length; i++) {
var gridItemCell = this.ContentGridItemRow.cells.item(i);
var helperElement = gridItemCell.firstChild;
var helperWidth = parseInt(String(helperElement.offsetWidth));
this.FreezeCellWidths.push(helperWidth);
helperElement.style.width = helperWidth + "px";
helperElement = this.HeaderGridHeaderCells[i].firstChild;
helperElement.style.width = helperWidth + "px";
}
for (var i = 0; i < this.FreezeHeaderRowCount; i++) {
this.ContentGridHeaderRows[i].style.display = "none";
}
};
GridViewScroll.prototype.appendFreezeHeader = function () {
this.HeaderFreeze = document.createElement('div');
this.HeaderFreeze.id = this.GridID + "_Header_Freeze";
this.HeaderFreeze.style.position = "absolute";
this.HeaderFreeze.style.overflow = "hidden";
this.HeaderFreeze.style.top = "0px";
this.HeaderFreeze.style.left = "0px";
this.HeaderFreeze.style.width = "";
this.HeaderFreezeGrid = this.HeaderGrid.cloneNode(false);
this.HeaderFreezeGrid.id = this.GridID + "_Header_Freeze_Grid";
this.HeaderFreezeGrid = this.HeaderFreeze.appendChild(this.HeaderFreezeGrid);
this.HeaderFreezeGridHeaderRows = new Array();
for (var i = 0; i < this.HeaderGridHeaderRows.length; i++) {
var headerFreezeGridHeaderRow = this.HeaderGridHeaderRows[i].cloneNode(false);
this.HeaderFreezeGridHeaderRows.push(headerFreezeGridHeaderRow);
var columnIndex = 0;
var columnCount = 0;
while (columnCount < this.FreezeColumnCount) {
var freezeColumn = this.HeaderGridHeaderRows[i].cells.item(columnIndex).cloneNode(true);
headerFreezeGridHeaderRow.appendChild(freezeColumn);
columnCount += freezeColumn.colSpan;
columnIndex++;
}
this.HeaderFreezeGrid.appendChild(headerFreezeGridHeaderRow);
}
this.HeaderFreeze = this.Header.appendChild(this.HeaderFreeze);
};
GridViewScroll.prototype.appendFreezeContent = function () {
this.ContentFreeze = document.createElement('div');
this.ContentFreeze.id = this.GridID + "_Content_Freeze";
this.ContentFreeze.style.position = "absolute";
this.ContentFreeze.style.overflow = "hidden";
this.ContentFreeze.style.top = "0px";
this.ContentFreeze.style.left = "0px";
this.ContentFreeze.style.width = "";
this.ContentFreezeGrid = this.HeaderGrid.cloneNode(false);
this.ContentFreezeGrid.id = this.GridID + "_Content_Freeze_Grid";
this.ContentFreezeGrid = this.ContentFreeze.appendChild(this.ContentFreezeGrid);
var freezeCellHeights = [];
var paddingTop = this.getPaddingTop(this.ContentGridItemRow.cells.item(0));
var paddingBottom = this.getPaddingBottom(this.ContentGridItemRow.cells.item(0));
for (var i = 0; i < this.ContentGrid.rows.length; i++) {
var gridItemRow = this.ContentGrid.rows.item(i);
var gridItemCell = gridItemRow.cells.item(0);
var helperElement = void 0;
if (gridItemCell.firstChild.className == "gridViewScrollHelper") {
helperElement = gridItemCell.firstChild;
}
else {
helperElement = this.appendHelperElement(gridItemCell);
}
var helperHeight = parseInt(String(gridItemCell.offsetHeight - paddingTop - paddingBottom));
freezeCellHeights.push(helperHeight);
var cgridItemRow = gridItemRow.cloneNode(false);
var cgridItemCell = gridItemCell.cloneNode(true);
if (this.FreezeColumnCssClass != null || this.FreezeColumnCssClass != "")
cgridItemRow.className = this.FreezeColumnCssClass;
var columnIndex = 0;
var columnCount = 0;
while (columnCount < this.FreezeColumnCount) {
var freezeColumn = gridItemRow.cells.item(columnIndex).cloneNode(true);
cgridItemRow.appendChild(freezeColumn);
columnCount += freezeColumn.colSpan;
columnIndex++;
}
this.ContentFreezeGrid.appendChild(cgridItemRow);
}
for (var i = 0; i < this.ContentGrid.rows.length; i++) {
var gridItemRow = this.ContentGrid.rows.item(i);
var gridItemCell = gridItemRow.cells.item(0);
var cgridItemRow = this.ContentFreezeGrid.rows.item(i);
var cgridItemCell = cgridItemRow.cells.item(0);
var helperElement = gridItemCell.firstChild;
helperElement.style.height = String(freezeCellHeights[i]) + "px";
helperElement = cgridItemCell.firstChild;
helperElement.style.height = String(freezeCellHeights[i]) + "px";
}
if (this.IsVerticalScrollbarEnabled) {
this.ContentFreeze.style.height = String(this.Height - this.Header.offsetHeight - this.ScrollbarWidth) + "px";
}
else {
this.ContentFreeze.style.height = String(this.ContentFixed.offsetHeight - this.ScrollbarWidth) + "px";
}
this.ContentFreeze = this.Content.appendChild(this.ContentFreeze);
};
GridViewScroll.prototype.appendFreezeFooter = function () {
this.FooterFreeze = document.createElement('div');
this.FooterFreeze.id = this.GridID + "_Footer_Freeze";
this.FooterFreeze.style.position = "absolute";
this.FooterFreeze.style.overflow = "hidden";
this.FooterFreeze.style.left = "0px";
this.FooterFreeze.style.width = String(this.ContentFixed.offsetWidth - this.ScrollbarWidth) + "px";
this.FooterFreezeGrid = this.HeaderGrid.cloneNode(false);
this.FooterFreezeGrid.id = this.GridID + "_Footer_Freeze_Grid";
this.FooterFreezeGrid = this.FooterFreeze.appendChild(this.FooterFreezeGrid);
this.FooterFreezeGridHeaderRow = this.ContentGridFooterRow.cloneNode(true);
if (this.FreezeFooterCssClass != null || this.FreezeFooterCssClass != "")
this.FooterFreezeGridHeaderRow.className = this.FreezeFooterCssClass;
for (var i = 0; i < this.FooterFreezeGridHeaderRow.cells.length; i++) {
var cgridHeaderCell = this.FooterFreezeGridHeaderRow.cells.item(i);
var helperElement = this.appendHelperElement(cgridHeaderCell);
helperElement.style.width = String(this.FreezeCellWidths[i]) + "px";
}
this.FooterFreezeGridHeaderRow = this.FooterFreezeGrid.appendChild(this.FooterFreezeGridHeaderRow);
this.FooterFreeze = this.Content.appendChild(this.FooterFreeze);
var footerFreezeTop = this.ContentFixed.offsetHeight - this.FooterFreeze.offsetHeight;
if (this.IsHorizontalScrollbarEnabled) {
footerFreezeTop -= this.ScrollbarWidth;
}
this.FooterFreeze.style.top = String(footerFreezeTop) + "px";
};
GridViewScroll.prototype.appendFreezeFooterColumn = function () {
this.FooterFreezeColumn = document.createElement('div');
this.FooterFreezeColumn.id = this.GridID + "_Footer_FreezeColumn";
this.FooterFreezeColumn.style.position = "absolute";
this.FooterFreezeColumn.style.overflow = "hidden";
this.FooterFreezeColumn.style.left = "0px";
this.FooterFreezeColumn.style.width = "";
this.FooterFreezeColumnGrid = this.HeaderGrid.cloneNode(false);
this.FooterFreezeColumnGrid.id = this.GridID + "_Footer_FreezeColumn_Grid";
this.FooterFreezeColumnGrid = this.FooterFreezeColumn.appendChild(this.FooterFreezeColumnGrid);
this.FooterFreezeColumnGridHeaderRow = this.FooterFreezeGridHeaderRow.cloneNode(false);
this.FooterFreezeColumnGridHeaderRow = this.FooterFreezeColumnGrid.appendChild(this.FooterFreezeColumnGridHeaderRow);
if (this.FreezeFooterCssClass != null)
this.FooterFreezeColumnGridHeaderRow.className = this.FreezeFooterCssClass;
var columnIndex = 0;
var columnCount = 0;
while (columnCount < this.FreezeColumnCount) {
var freezeColumn = this.FooterFreezeGridHeaderRow.cells.item(columnIndex).cloneNode(true);
this.FooterFreezeColumnGridHeaderRow.appendChild(freezeColumn);
columnCount += freezeColumn.colSpan;
columnIndex++;
}
var footerFreezeTop = this.ContentFixed.offsetHeight - this.FooterFreeze.offsetHeight;
if (this.IsHorizontalScrollbarEnabled) {
footerFreezeTop -= this.ScrollbarWidth;
}
this.FooterFreezeColumn.style.top = String(footerFreezeTop) + "px";
this.FooterFreezeColumn = this.Content.appendChild(this.FooterFreezeColumn);
};
GridViewScroll.prototype.appendHelperElement = function (gridItemCell) {
var helperElement = document.createElement('div');
helperElement.className = "gridViewScrollHelper";
while (gridItemCell.hasChildNodes()) {
helperElement.appendChild(gridItemCell.firstChild);
}
return gridItemCell.appendChild(helperElement);
};
GridViewScroll.prototype.getScrollbarWidth = function () {
var innerElement = document.createElement('p');
innerElement.style.width = "100%";
innerElement.style.height = "200px";
var outerElement = document.createElement('div');
outerElement.style.position = "absolute";
outerElement.style.top = "0px";
outerElement.style.left = "0px";
outerElement.style.visibility = "hidden";
outerElement.style.width = "200px";
outerElement.style.height = "150px";
outerElement.style.overflow = "hidden";
outerElement.appendChild(innerElement);
document.body.appendChild(outerElement);
var innerElementWidth = innerElement.offsetWidth;
outerElement.style.overflow = 'scroll';
var outerElementWidth = innerElement.offsetWidth;
if (innerElementWidth === outerElementWidth)
outerElementWidth = outerElement.clientWidth;
document.body.removeChild(outerElement);
return innerElementWidth - outerElementWidth;
};
GridViewScroll.prototype.isRTL = function () {
var direction = "";
if (window.getComputedStyle) {
direction = window.getComputedStyle(this.ContentGrid, null).getPropertyValue('direction');
}
else {
direction = this.ContentGrid.currentStyle.direction;
}
return direction === "rtl";
};
GridViewScroll.prototype.getPaddingTop = function (element) {
var value = "";
if (window.getComputedStyle) {
value = window.getComputedStyle(element, null).getPropertyValue('padding-Top');
}
else {
value = element.currentStyle.paddingTop;
}
return parseInt(value);
};
GridViewScroll.prototype.getPaddingBottom = function (element) {
var value = "";
if (window.getComputedStyle) {
value = window.getComputedStyle(element, null).getPropertyValue('padding-Bottom');
}
else {
value = element.currentStyle.paddingBottom;
}
return parseInt(value);
};
GridViewScroll.prototype.undo = function () {
this.undoHelperElement();
for (var _i = 0, _a = this.ContentGridHeaderRows; _i < _a.length; _i++) {
var contentGridHeaderRow = _a[_i];
contentGridHeaderRow.style.display = "";
}
this.Parent.insertBefore(this.ContentGrid, this.Header);
this.Parent.removeChild(this.Header);
this.Parent.removeChild(this.Content);
this._initialized = false;
};
GridViewScroll.prototype.undoHelperElement = function () {
for (var i = 0; i < this.ContentGridItemRow.cells.length; i++) {
var gridItemCell = this.ContentGridItemRow.cells.item(i);
var helperElement = gridItemCell.firstChild;
while (helperElement.hasChildNodes()) {
gridItemCell.appendChild(helperElement.firstChild);
}
gridItemCell.removeChild(helperElement);
}
if (this.FreezeColumn) {
for (var i = 2; i < this.ContentGrid.rows.length; i++) {
var gridItemRow = this.ContentGrid.rows.item(i);
var gridItemCell = gridItemRow.cells.item(0);
var helperElement = gridItemCell.firstChild;
while (helperElement.hasChildNodes()) {
gridItemCell.appendChild(helperElement.firstChild);
}
gridItemCell.removeChild(helperElement);
}
}
};
return GridViewScroll;
}());
//add On Head
<head runat="server">
<title></title>
<script src="client/js/jquery-3.1.1.min.js"></script>
<script src="js/gridviewscroll.js"></script>
<script type="text/javascript">
window.onload = function () {
var gridViewScroll = new GridViewScroll({
elementID: "GridView1" // [Header is fix column will be Freeze ][1]Target Control
});
gridViewScroll.enhance();
}
</script>
</head>
//Add on Body
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">
// <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<%-- <Columns>
<asp:BoundField DataField="SHIPMENT_ID" HeaderText="SHIPMENT_ID"
ReadOnly="True" SortExpression="SHIPMENT_ID" />
<asp:BoundField DataField="TypeValue" HeaderText="TypeValue"
SortExpression="TypeValue" />
<asp:BoundField DataField="CHAId" HeaderText="CHAId"
SortExpression="CHAId" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
</Columns>--%>
</asp:GridView>
<script type="text/javascript">
$(document).ready(function () {
var gridHeader = $('#<%=grdSiteWiseEmpAttendance.ClientID%>').clone(true); // Here Clone Copy of Gridview with style
$(gridHeader).find("tr:gt(0)").remove(); // Here remove all rows except first row (header row)
$('#<%=grdSiteWiseEmpAttendance.ClientID%> tr th').each(function (i) {
// Here Set Width of each th from gridview to new table(clone table) th
$("th:nth-child(" + (i + 1) + ")", gridHeader).css('width', ($(this).width()).toString() + "px");
});
$("#GHead1").append(gridHeader);
$('#GHead1').css('position', 'top');
$('#GHead1').css('top', $('#<%=grdSiteWiseEmpAttendance.ClientID%>').offset().top);
});
</script>
<div class="row">
<div class="col-lg-12" style="width: auto;">
<div id="GHead1"></div>
<div id="divGridViewScroll1" style="height: 600px; overflow: auto">
<div class="table-responsive">
<asp:GridView ID="grdSiteWiseEmpAttendance" CssClass="table table-small-font table-bordered table-striped" Font-Size="Smaller" EmptyDataRowStyle-ForeColor="#cc0000" HeaderStyle-Font-Size="8" HeaderStyle-Font-Names="Calibri" HeaderStyle-Font-Italic="true" runat="server" AutoGenerateColumns="false"
BackColor="#f0f5f5" OnRowDataBound="grdSiteWiseEmpAttendance_RowDataBound" HeaderStyle-ForeColor="#990000">
<Columns>
</Columns>
<HeaderStyle HorizontalAlign="Justify" VerticalAlign="Top" />
<RowStyle Font-Names="Calibri" ForeColor="#000000" />
</asp:GridView>
</div>
</div>
</div>
</div>
Acheived by using java script...
Copy and paste given below javascript code inside the head tag.
<script language="javascript" type="text/javascript">
function MakeStaticHeader(gridId, height, width, headerHeight, isFooter) {
var tbl = document.getElementById(gridId);
if (tbl) {
var DivHR = document.getElementById('DivHeaderRow');
var DivMC = document.getElementById('DivMainContent');
var DivFR = document.getElementById('DivFooterRow');
//*** Set divheaderRow Properties ****
DivHR.style.height = headerHeight + 'px';
DivHR.style.width = (parseInt(width) - 16) + 'px';
DivHR.style.position = 'relative';
DivHR.style.top = '0px';
DivHR.style.zIndex = '10';
DivHR.style.verticalAlign = 'top';
//*** Set divMainContent Properties ****
DivMC.style.width = width + 'px';
DivMC.style.height = height + 'px';
DivMC.style.position = 'relative';
DivMC.style.top = -headerHeight + 'px';
DivMC.style.zIndex = '1';
//*** Set divFooterRow Properties ****
DivFR.style.width = (parseInt(width) - 16) + 'px';
DivFR.style.position = 'relative';
DivFR.style.top = -headerHeight + 'px';
DivFR.style.verticalAlign = 'top';
DivFR.style.paddingtop = '2px';
if (isFooter) {
var tblfr = tbl.cloneNode(true);
tblfr.removeChild(tblfr.getElementsByTagName('tbody')[0]);
var tblBody = document.createElement('tbody');
tblfr.style.width = '100%';
tblfr.cellSpacing = "0";
tblfr.border = "0px";
tblfr.rules = "none";
//*****In the case of Footer Row *******
tblBody.appendChild(tbl.rows[tbl.rows.length - 1]);
tblfr.appendChild(tblBody);
DivFR.appendChild(tblfr);
}
//****
DivHR.appendChild(tbl.cloneNode(true));
}
}
function OnScrollDiv(Scrollablediv) {
document.getElementById('DivHeaderRow').scrollLeft = Scrollablediv.scrollLeft;
document.getElementById('DivFooterRow').scrollLeft = Scrollablediv.scrollLeft;
}
</script>
Then Copy this code and paste and place your Grid View inside DivMainContent.
HTML Code:-
<div id="DivRoot" align="left">
<div style="overflow: hidden;" id="DivHeaderRow">
</div>
<div style="overflow:scroll;" onscroll="OnScrollDiv(this)" id="DivMainContent">
<%-- ***Place Your GridView Here***
<asp:GridView runat="server" ID="gridshow" Width="100%"
AutoGenerateColumns="False"ShowFooter="True">
<Columns>
//...................
</Columns>
</asp:GridView>
--%>
</div>
<div id="DivFooterRow" style="overflow:hidden">
</div>
</div>
Then Call function MakeStaticHeader in Aspx.CS File at the time of binding Gridview and pass the Some parameters.
ClientId of Gridview(Change GrdDisplay.ClientID as your gridview clientid).
Height of Scrollable div.
Width of Scrollable div.
Height of Table Header Row.
IsFooter (true/false) If you want to Make footer static or not.
-->After binding the Gridview, place below code
ScriptManager.RegisterStartupScript(Page, this.GetType(), "Key", "<script>MakeStaticHeader('" + GrdDisplay.ClientID + "', 400, 950 , 40 ,true); </script>", false);
Hope this will work for sure...

customize the filter option for a date colmn telerik grid

I am using telerik grid. I need to apply a filter for all the columns in my grid. Currenly I am customizing the filter option using the following code. By using the following code, I am removing the certain items for all the columns. But, for a date column could any one please tell me what are the possible options for filtering in the grid and how to customize those filtering options?
Code Behind
protected void RGVTest_Init(object sender, EventArgs e)
{
GridFilterMenu menu = RGVTest.FilterMenu;
int i = 0;
while (i < menu.Items.Count)
{
if (menu.Items[i].Text == "Between" ||
menu.Items[i].Text == "NotBetween")
{
menu.Items.RemoveAt(i);
}
else
{
i++;
}
}
}
*Aspx:*
<telerik:RadGrid ID="RGVTest" runat="server" Skin="Vista" AllowPaging="True"
AllowFilteringByColumn="true" AllowSorting="true" GridLines="None" OnItemCommand="RGVTest_ItemCommand"
PageSize="10" OnNeedDataSource="RGVTest_NeedDataSource" OnItemDataBound="RGVTest_ItemDataBound"
OnInit="RGVTest_Init">
<GroupingSettings CaseSensitive="false" />
<PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
<MasterTableView AutoGenerateColumns="False" CellSpacing="-1" >
<NoRecordsTemplate>
<div style="color: red">
No Records to display!
</div>
</NoRecordsTemplate>
<Columns>
<telerik:GridTemplateColumn DataField="SSN" ReadOnly="True" HeaderText="SSN" UniqueName="SSN"
SortExpression="SSN">
<ItemTemplate>
<asp:Label ID="LblSSN" runat="server" Text='<%#Eval("SSN") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="5%" />
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="Date" HeaderText="Date" UniqueName="Date"
SortExpression="Date">
<ItemTemplate>
<asp:Label ID="LblDate" runat="server" Text='<%#Eval("Date","{0:MM/dd/yyyy}") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="4%" />
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
you do like this way:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName)
{
Pair filterPair = e.CommandArgument as Pair;
string columnName = Convert.ToString(filterPair.Second);
if (columnName == "CreationDate")
{
e.Canceled = true;
string date = ((TextBox)((GridFilteringItem)e.Item)[Convert.ToString(filterPair.Second)].Controls [0]).Text;
DateTime startDate = Convert.ToDateTime(date);
DateTime endDate = startDate.AddDays(1);
string newFilter = "('" + startDate.ToString("MM/dd/yyyy") + "' <= [CreationDate] AND [CreationDate] <= '" + endDate.ToString("MM/dd/yyyy") + "')";
GridBoundColumn dateColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe(columnName);
dateColumn.CurrentFilterValue = startDate.ToString("MM/dd/yyyy");
RadGrid1.MasterTableView.FilterExpression = newFilter;
RadGrid1.Rebind();
}
}
}
Try like this
function FilterMenuShowing(sender, eventArgs)
{
if (eventArgs.get_column().get_uniqueName() == "IsPostable")
{
var menu = eventArgs.get_menu();
var items = menu._itemData;
var i = 0;
while (i < items.length)
{
if (items[i].value != "NoFilter" && items[i].value != "EqualTo" && items[i].value != "NotEqualTo")
{
var item = menu._findItemByValue(items[i].value);
if (item != null)
item._element.style.display="none";
}
i++;
}
}
else
{
var menu = eventArgs.get_menu();
var items = menu._itemData;
var i = 0;
while (i < items.length)
{
var item = menu._findItemByValue(items[i].value);
if (item != null)
item._element.style.display="";
i++;
}
}
}
On your grid add-
<ClientSettings>
<ClientEvents OnFilterMenuShowing="filterMenuShowing" />
</ClientSettings>
See details here
You can try the way its done below for "order date" column.
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName &&
((Pair)e.CommandArgument).Second.ToString() == "OrderDate"
&&
((Pair)e.CommandArgument).First != "NoFilter")
{
e.Canceled = true;
GridFilteringItem filterItem = (GridFilteringItem)e.Item;
string currentPattern = (filterItem[((Pair)e.CommandArgument).Second.ToString()].Controls[0] as TextBox).Text;
string filterPattern = "";
string filterPatternAssist = "";
if (currentPattern.IndexOf(" ") != -1)
{
currentPattern = currentPattern.Replace(" ", "/");
}
string[] vals = currentPattern.Split("/".ToCharArray());
string filterOption = (e.CommandArgument as Pair).First.ToString();
if (filterOption != "IsNull" && filterOption != "NotIsNull")
{
if (vals.Length > 3)
{
filterPatternAssist = vals[4] + "/" + vals[3] + "/" + vals[5];
}
filterPattern = vals[1] + "/" + vals[0] + "/" + vals[2];
}
GridBoundColumn dateColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("OrderDate");
switch (filterOption)
{
case "EqualTo":
filterPattern = "[OrderDate] = '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
break;
case "NotEqualTo":
filterPattern = "Not [OrderDate] = '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.NotEqualTo;
break;
case "GreaterThan":
filterPattern = "[OrderDate] > '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.GreaterThan;
break;
case "LessThan":
filterPattern = "[OrderDate] < '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.LessThan;
break;
case "GreaterThanOrEqualTo":
filterPattern = "[OrderDate] >= '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.GreaterThanOrEqualTo;
break;
case "LessThanOrEqualTo":
filterPattern = "[OrderDate] <= '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.LessThanOrEqualTo;
break;
case "Between":
filterPattern = "'" + filterPattern + "' <= [OrderDate] AND [OrderDate] <= '" + filterPatternAssist + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.Between;
break;
case "NotBetween":
filterPattern = "[OrderDate] <= '" + filterPattern + "' OR [OrderDate] >= '" + filterPatternAssist + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.NotBetween;
break;
case "IsNull":
break;
case "NotIsNull":
break;
}
foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
{
if (column.UniqueName != "OrderDate")
{
column.CurrentFilterFunction = GridKnownFunction.NoFilter;
column.CurrentFilterValue = string.Empty;
}
}
Session["filterPattern"] = filterPattern;
dateColumn.CurrentFilterValue = currentPattern;
filterItem.OwnerTableView.Rebind();
}
//Add more conditional checks for commands here if necessary
else if (e.CommandName != RadGrid.SortCommandName && e.CommandName != RadGrid.PageCommandName)
{
Session["filterPattern"] = null;
GridBoundColumn dateColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("OrderDate");
dateColumn.CurrentFilterFunction = GridKnownFunction.NoFilter;
dateColumn.CurrentFilterValue = string.Empty;
}
}

Resources