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.
Related
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);
}
}
UI:-
<asp:GridView ID="GridView" OnPageIndexChanging="GridView1_PageIndexChanging" runat="server" AllowPaging="True" OnRowCreated="onrow_databound" ShowFooter="True" AllowSorting="True" OnSelectedIndexChanged="GridView_SelectedIndexChanged" GridLines="Both" CssClass="mydatagrid" PagerStyle-CssClass="pager"
HeaderStyle-CssClass="header" RowStyle-CssClass="rows" ForeColor="#3366FF" PageSize="4" >
<columns>
<asp:TemplateField >
<FooterTemplate>
<asp:Button ID="Button1" runat="server" Text="Insert" Height="31px" OnClick="AddButton_Click" BorderStyle="Solid" BorderColor="Black" BackColor="#6699FF" />
</FooterTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
aspx:- Binding the data and then creating dropdown at footer with on_row_bound for submission:
protected void onrow_databound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
for (int i = 1; i < e.Row.Cells.Count; i++)
{
TextBox txt = new TextBox();
DropDownList dr = new DropDownList();
if (i == 1)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectionConn"].ConnectionString);
List<string> values = new List<string>();
string sql = #"Select spnd_type_dsc from [dbo].[proj_spnd_type]";
using (var command = new SqlCommand(sql, con))
{
int r = 0;
con.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
values.Add(reader.GetString(r).TrimEnd(' '));
}
dr.ID = ID;
for (int j = 0; j < values.Count; j++)
{
dr.Items.Add(new ListItem(values[j]));
}
dr.AutoPostBack = false;
e.Row.Cells[i].Controls.Add(dr);
}
}
else if (i == 2)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectionConn"].ConnectionString);
string name = dr.SelectedValue;
List<string> values = new List<string>();
string sql = #"Select [prtnr_nm] from [dbo].[proj_prtnr] j inner join [dbo].[proj_spnd_type] r on j.[spnd_ty_id] =r.[spnd_type_id] where spnd_type_dsc= '" + name + "'";
using (var command = new SqlCommand(sql, con))
{
int r = 0;
con.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
values.Add(reader.GetString(r));
}
DropDownList dk = new DropDownList();
dk.ID = ID;
dk.Items.Add(new ListItem("--Select--", ""));
for (int j = 0; j < values.Count; j++)
{
dk.Items.Add(new ListItem(values[j], values[j]));
}
dk.AutoPostBack = false;
e.Row.Cells[i].Controls.Add(dk);
}
}
else if (i == 3)//Geo
{
var roleList = (List<string>)Session["Geo"];
if (roleList.Count == 1)
{
txt.Text = roleList[0].ToString();
txt.Enabled = false;
e.Row.Cells[i].Controls.Add(txt);
}
else
{
DropDownList dd = new DropDownList();
dd.ID = ID;
dd.Items.Add(new ListItem("--Select--", ""));
for (int j = 0; j < roleList.Count; j++)
{
dd.Items.Add(new ListItem(roleList[j], roleList[j]));
}
dd.AutoPostBack = false;
e.Row.Cells[i].Controls.Add(dd);
}
}
else
{
e.Row.Cells[i].Controls.Add(txt);
}
}
}
}
After putting the postback in the first dropdown. I am unable to retrieve the selected value
I am creating a datatable and adding rows dynamically and am binding datatable to gridview when there are no records am displaying as no records found using emptydatatext but this is not working.Here is my code
protected void show_fence_report(object sender, EventArgs e)
{
int drp_fence_id = common.make_int(common.get_request("drp_fence"));
string fence_start_date_time1 = common.get_request("fence_start_date_time");
string fence_end_date_time1 = common.get_request("fence_end_date_time");
//Delete data from datatable and gridview
dt_fence.Clear();
if (gridview_fence.DataSource != null)
{
((DataView)gridview_fence.DataSource).Table.Clear();
}
gridview_fence.DataBind();
gridview_fence.EmptyDataText = "Records Not Found";
hid_fence_id.Value = drp_fence_id.ToString();
hid_fence_start_datetime.Value = fence_start_date_time1;
hid_fence_end_datetime.Value = fence_end_date_time1;
display_fence_report();
gridview_fence.EmptyDataText = "Records Not Found";
}
public void display_fence_report()
{
string fence_id1 = "", fence_name1, fence_type1 = "", fence_status;
float default_size = 100000, landmark_latitude1 = 0, landmark_longitude1 = 0, fence_latitude1 = 0, fence_longitude1 = 0, fence_size1 = 0, longitude_x = 0, latitude_y = 0;
int points_polygon = 0;
ArrayList vertices_x = new ArrayList();
ArrayList vertices_y = new ArrayList();
query = "select latitude,longitude,added_date_time,speed,location,(select object_value from tracking_master_objects where object_id = a.object_id) as object from tracking_data_domain a where object_id in(select object_id from tracking_assign_fence a where fence_id = '" + hid_fence_id.Value + "' and is_active = '1') and (added_date_time between convert(datetime, '" + hid_fence_start_datetime.Value + "', 105) and convert(datetime, '" + hid_fence_end_datetime.Value + "', 105)) order by gps_id asc";
dr = common.run_query(query, db, cm, dr, 0);
if (dr.HasRows)
{
//To Build Fence Latitudes and Longitudes
query = "select fence_id,fence_name,fence_type,landmark_latitude,landmark_longitude,fence_latitude,fence_longitude,fence_size from tracking_master_fences where domain_id = '" + domain_id1 + "' and fence_id = '" + hid_fence_id.Value + "' and is_active = '1'";
dr2 = common.get_row(query, db2, cm2, dr2, 0);
if (dr2.HasRows)
{
fence_id1 = dr2["fence_id"].ToString();
fence_name1 = dr2["fence_name"].ToString();
fence_type1 = dr2["fence_type"].ToString();
landmark_latitude1 = common.make_float(dr2["landmark_latitude"].ToString());//fs_lat
landmark_longitude1 = common.make_float(dr2["landmark_longitude"].ToString());//fs_long
fence_latitude1 = common.make_float(dr2["fence_latitude"].ToString());//sec_lat
fence_longitude1 = common.make_float(dr2["fence_longitude"].ToString());//sec_long
fence_size1 = common.make_float(dr2["fence_size"].ToString());
}
dr2.Close();
//Build POlygon Vertices
if (fence_type1 == "4")
{
query = "select polygon_latitude,polygon_longitude from tracking_master_fence_polygons where fence_id = '" + hid_fence_id.Value + "' and domain_id = '" + domain_id1 + "'";
dr1 = common.run_query(query, db1, cm1, dr1, 0);
if (dr1.HasRows)
{
while (dr1.Read())
{
vertices_x.Add(dr1["polygon_latitude"]);
vertices_y.Add(dr1["polygon_longitude"]);
}
}
dr1.Close();
points_polygon = vertices_x.Count;
}
//Create a Datatable of 14 rows
dt_fence.Columns.Add("fence_id", typeof(string));
dt_fence.Columns.Add("Date", typeof(string));
dt_fence.Columns.Add("Speed", typeof(string));
dt_fence.Columns.Add("Location", typeof(string));
dt_fence.Columns.Add("landmark_latitude", typeof(string));
dt_fence.Columns.Add("landmark_longitude", typeof(string));
dt_fence.Columns.Add("fence_latitude", typeof(string));
dt_fence.Columns.Add("fence_longitude", typeof(string));
dt_fence.Columns.Add("latitude", typeof(string));
dt_fence.Columns.Add("longitude", typeof(string));
dt_fence.Columns.Add("fence_size", typeof(string));
dt_fence.Columns.Add("fence_type", typeof(string));
dt_fence.Columns.Add("fence_status", typeof(string));
dt_fence.Columns.Add("object", typeof(string));
while (dr.Read())
{
fence_status = "";
float latitude = common.make_float(dr["latitude"].ToString());
float longitude = common.make_float(dr["longitude"].ToString());
if (fence_type1 == "1" || fence_type1 == "2")
{
if (((landmark_latitude1 * 100000) < (latitude * 100000) && (fence_latitude1 * 100000) > (latitude * 100000)) && ((landmark_longitude1 * 100000) < (longitude * 100000) && (fence_longitude1 * 100000) > (longitude * 100000)))
{
fence_status = "Inside";
}
else
{
fence_status = "Outside";
}
}
else if (fence_type1 == "3")
{
float ft = ((latitude * 100000) - (landmark_latitude1 * 100000));
float st = ((longitude * 100000) - (landmark_longitude1 * 100000));
float sqrt = common.make_float(Math.Sqrt((ft * ft) + (st * st)).ToString());
if (fence_size1 < sqrt)
{
fence_status = "Out Side";
}
else
{
fence_status = "In Side";
}
}
else if (fence_type1 == "4")
{
longitude_x = common.make_float(dr["latitude"].ToString());
latitude_y = common.make_float(dr["longitude"].ToString());
int i = 0, j = 0, c = 0;
for (i = 0, j = points_polygon - 1; i < points_polygon; j = i++)
{
float vertices_y_i_val = common.make_float(vertices_y[i].ToString());
float vertices_y_j_val = common.make_float(vertices_y[j].ToString());
float vertices_x_i_val = common.make_float(vertices_x[i].ToString());
float vertices_x_j_val = common.make_float(vertices_x[j].ToString());
if (((vertices_y_i_val > latitude_y != (vertices_y_j_val > latitude_y)) &&
(longitude_x < (vertices_x_j_val - vertices_x_i_val) * (latitude_y - vertices_y_i_val) / (vertices_y_j_val - vertices_y_i_val) + vertices_x_i_val)))
{
c = 1;
}
}
if (c == 1)
{
fence_status = "In Side";
}
else
{
fence_status = "Out Side";
}
}
dt_fence.Rows.Add(fence_id1, dr["added_date_time"], dr["speed"], dr["location"], landmark_latitude1, landmark_longitude1, fence_latitude1, fence_longitude1, latitude, longitude, fence_size1, fence_type1, fence_status, dr["object"]);
}//End of while Loop
//hid_ds_fence.Value = dt_fence.ToString();
gridview_fence.DataSource = dt_fence;
gridview_fence.DataBind();
}
dr.Close();
fence_modalpopup.Show();
}
In your code you're assigning EmptyDataText value after DataBind. It should be before DataBind. If "Message" is not going to change, you should rather define in HTML source as suggested.
You can use something like this
<Columns>
<Columns>
<EmptyDataTemplate>
<asp:Label ID="lblEmptydata" runat="server" Text="No Data here"></asp:Label>
</EmptyDataTemplate>
</asp:GridView>
Or can try this
in my remark gridview's row_databoundevent i wrote
if (e.Row.Cells[0].Text == " ") // to display text when there is no data
{
e.Row.Cells[0].Text = "No Data Found";
}
Or can try this too
dt.Rows.Add(dt.NewRow());
grid1.DataSource = dt;
grid1.DataBind();
int totalcolums = grid1.Rows[0].Cells.Count;
grid1.Rows[0].Cells.Clear();
grid1.Rows[0].Cells.Add(new TableCell());
grid1.Rows[0].Cells[0].ColumnSpan = totalcolums;
grid1.Rows[0].Cells[0].Text = "No Data Found";
protected void btnedit_Click1(object sender, EventArgs e)
{
dt = (DataTable)ViewState["qualification"];
int Id;
foreach (GridViewRow row in gvqualification.Rows)
{
RadioButton rb = (RadioButton)row.FindControl("rdoselect");
HiddenField HFI = (HiddenField)row.FindControl("autoid");
HiddenField HFE = (HiddenField)row.FindControl("qualificationid");
Label lbleducational = (Label)row.FindControl("lbgeducationallevel");
Label lblcollege = (Label)row.FindControl("lbgcollege");
Label lbluniversity = (Label)row.FindControl("lbguniversity");
Label lblspecialization = (Label)row.FindControl("lbgspecialization");
Label lblscore = (Label)row.FindControl("lbgscore");
Label lblstartyear = (Label)row.FindControl("lbgstartyear");
Label lblyearofcompletion = (Label)row.FindControl("lbgyearofcompletion");
Label lblstate = (Label)row.FindControl("lbgstate");
Label lblcountry = (Label)row.FindControl("lbgcountry");
if (rb.Checked)
{
Id = int.Parse(HFI.Value);
hqualificationid.Value = HFE.Value;
txteducationallevel.Text = lbleducational.Text;
txtcollegename.Text = lblcollege.Text;
txtuniversity.Text = lbluniversity.Text;
txtspecialization.Text = lblspecialization.Text;
txtscore.Text = lblscore.Text;
ddlstartyear.Text = lblstartyear.Text;
ddlyearofcompletion.Text = lblyearofcompletion.Text;
txtstate.Text = lblstate.Text;
txtcountry.Text = lblcountry.Text;
dt = (DataTable)ViewState["qualification"];
int index = -1;
try
{
foreach (DataRow dr in dt.Rows)
{
index = index + 1;
if (dr["ID"].ToString() == Id.ToString())
{
dt.Rows[index].Delete();
ViewState["qualification"] = dt;
btnremove.Visible = false;
}
}
}
catch (Exception E)
{
dt = (DataTable)ViewState["qualification"];
gvqualification.DataSource = dt;
gvqualification.DataBind();
}
}
}
}
GridView has property "EmptyDataText" it set the text if no data.
<asp:GridView ID="grid" runat="server" EmptyDataText="No Record Found!" >
<column> --- </column>
</asp:GridView>
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;
}
}