Link to home
Start Free TrialLog in
Avatar of amillyard
amillyardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

datagridview

I have added an extra column in the datagridview as follows:

<asp:TemplateField HeaderText="Select" ShowHeader="False" >
            <ItemTemplate>
              <button type="button" OnClick="javascript:window.location = 'http://CaseTracking';">
                  View</button>
            </ItemTemplate>
          </asp:TemplateField>

BUT ... I would like this column to act like the command button type -- so it gets processed via the following scripting :

GridView_SellToProspect_RowCommand

(attached scripting)

at the moment when select the 'view' button -- this does not get processed currently .. i.e. is not call the GridView_SellTo...... routine.

how do I make the custom column operate this way please?
protected void GridView_SellToProspect_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                int rowIndex = Convert.ToInt32(e.CommandArgument);
 
                Session["CCClientCase_ID"] = Convert.ToInt32(GridView_SellToProspect.DataKeys[rowIndex].Values["ClientCase_ID"]);
                Session["CCMasterAccount_ID"] = Convert.ToInt32(GridView_SellToProspect.DataKeys[rowIndex].Values["MasterAccount_ID"]);
 
                Session["AccountMode"] = 3;
 
                UpdateCCClientCaseRecord();
                Response.Redirect("http://CaseTracking", true);
            }
        }

Open in new window

Avatar of Binuth
Binuth
Flag of India image

can u post full .aspx code?
Avatar of amillyard

ASKER

page scripts as requested.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyCallBacks_SellToProspect.aspx.cs" Inherits="FORTUNE.MyCallBacks.MyCallBacks_SellToProspect" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>FORTUNE AI</title>
    <link href="../App_Themes/fortune.css" rel="stylesheet" type="text/css">
    </head>
<html xmlns="http://www.w3.org/1999/xhtml" >
 
<body style="text-align: center">
    <form id="form1" runat="server">
        
        
        <asp:Panel ID="Panel_MyCallBacks_STP" runat="server">
  <div id="Div3" class="cssbox_fb" style="font-size: 12pt; width: 800px">
    <div class="cssbox_head_fb">
      <h2 style="height: 1%; text-align: left">
        <span style="font-size: 12pt; font-family: 'Arial Unicode MS'">
          My Call-Backs :: Sell to Prospect
            <span lang="en-gb">  
              <asp:Label ID="Label_Date" runat="server" Font-Names="Arial Unicode MS" Font-Size="X-Small" Visible="False"></asp:Label>
            </span>
        </span>
      </h2>
    </div>
    <div class="cssbox_body_fb" style="text-align: left">
      <asp:GridView ID="GridView_SellToProspect" runat="server" DataKeyNames="ClientCase_ID,MasterAccount_ID" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource_SellToProspect" Font-Names="Arial Unicode MS" Font-Size="10pt" GridLines="None" HorizontalAlign="Center" style="text-align: left" Width="715px" onrowcommand="GridView_SellToProspect_RowCommand" CellPadding="4" ForeColor="#333333" onload="GridView_SellToProspect_Load" onrowdatabound="GridView_SellToProspect_RowDataBound">
        <FooterStyle Font-Bold="True" ForeColor="White" BackColor="#5D7B9D" />
        <RowStyle BackColor="#F0F0F0" ForeColor="Black" />
        <Columns>
          <asp:BoundField DataField="ClientCase_ID" HeaderText="Client Case" SortExpression="ClientCase_ID" Visible="False" />
          
          <asp:TemplateField HeaderText="Select" ShowHeader="False" >
            <ItemTemplate>
              <button type="button" OnClick="javascript:window.location = 'http://CaseTracking';">
                  View</button>
            </ItemTemplate>
          </asp:TemplateField>
            <asp:BoundField DataField="MasterAccount_ID" HeaderText="Master Account" 
                SortExpression="MasterAccount_ID" Visible="False" />
            <asp:BoundField DataField="CallBackDate" DataFormatString="{0:dd-MMM-yy}" 
                HeaderText="Call-Back" SortExpression="CallBackDate" />
            <asp:BoundField DataField="DisplayCallBackTime" HeaderText="Schedule" 
                SortExpression="DisplayCallBackTime" />
            <asp:BoundField DataField="DisplayNameApp1" HeaderText="Primary Applicant" 
                SortExpression="DisplayNameApp1" />
            <asp:BoundField DataField="ActionNoteDesc" HeaderText="Action Note Description" 
                HtmlEncode="False" SortExpression="ActionNoteDesc" />
        </Columns>
        <PagerStyle ForeColor="Black" HorizontalAlign="Center" BackColor="White" VerticalAlign="Middle" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle Font-Bold="True" ForeColor="Black" BackColor="White" VerticalAlign="Middle" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="Black" VerticalAlign="Middle" />
      </asp:GridView>
      <br />
    </div>
  </div>
</asp:Panel>
 
            
            
            
                    <asp:SqlDataSource ID="SqlDataSource_SellToProspect" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:FORTUNEConnectionString %>" SelectCommand="SELECT an.ClientCase_ID, an.DisplayCallBackTime, an.CallBackDate, an.CallBackHour, an.CallBackMinute, an.ActionNoteDesc, cc.AssignedStaffMember, cc.MasterAccount_ID, cc.DisplayNameApp1 
 
FROM ActionNotes AS an INNER JOIN ClientCases AS cc ON cc.ClientCase_ID = an.ClientCase_ID INNER JOIN MasterAccounts AS ma ON ma.MasterAccount_ID = cc.MasterAccount_ID 
 
WHERE (an.ActionNoteType_ID = @ActionNoteType_ID) AND (cc.AssignedStaffMember = @AssignedStaffMember) AND (an.HistoricNote = 0) AND (an.SellToProspect = 1)
AND (an.CallBackDate &lt;= @SystemDate)
 
 ORDER BY an.CallBackDate, an.CallBackHour, an.CallBackMinute">
                        <SelectParameters>
                            <asp:Parameter DefaultValue="4" Name="ActionNoteType_ID" />
                            <asp:SessionParameter DefaultValue="" Name="AssignedStaffMember" 
                                SessionField="fortuneAgent_ID" />
                            <asp:ControlParameter ControlID="Label_Date" DefaultValue="" Name="SystemDate" 
                                PropertyName="Text" Type="DateTime" />
                        </SelectParameters>
                    </asp:SqlDataSource>       
    </form>
</body>
</html>
 
 
 
 
 
 
_________________
 
 
 
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using AI.Networks.DBnet;
using System.Drawing;
using System.Data.SqlClient;
 
namespace FORTUNE.MyCallBacks
{
    public partial class MyCallBacks_SellToProspect : System.Web.UI.Page
    {
        DB_Utils dbu = new DB_Utils();
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                FindLoggedInAgent();
                Label_Date.Text = DateTime.Now.ToString("ddd, MMM dd, yyyy");
            }
        }
 
        protected void GridView_SellToProspect_Load(object sender, EventArgs e)
        {
            GridView_SellToProspect.Columns[3].ItemStyle.Width = 73;    // Call-Back Date
            GridView_SellToProspect.Columns[4].ItemStyle.Width = 80;    // Call-Back Time
            GridView_SellToProspect.Columns[5].ItemStyle.Width = 200;   // Primary Applicant
            GridView_SellToProspect.Columns[6].ItemStyle.Width = 375;   // Action Note Desc
        }
 
        protected void GridView_SellToProspect_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                int rowIndex = Convert.ToInt32(e.CommandArgument);
 
                Session["CCClientCase_ID"] = Convert.ToInt32(GridView_SellToProspect.DataKeys[rowIndex].Values["ClientCase_ID"]);
                Session["CCMasterAccount_ID"] = Convert.ToInt32(GridView_SellToProspect.DataKeys[rowIndex].Values["MasterAccount_ID"]);
 
                Session["AccountMode"] = 3;
 
                UpdateCCClientCaseRecord();
                Response.Redirect("http://CaseTracking", true);
            }
        }
 
        protected void GridView_SellToProspect_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DateTime serverTime = DateTime.Now;
                Int32 dayDiff = Convert.ToDateTime(e.Row.Cells[3].Text).Subtract(serverTime).Days;
 
                switch (dayDiff)
                {
                    case -1: e.Row.BackColor = Color.LightYellow;
                        e.Row.ForeColor = Color.Black;
                        break;
                    case -2: e.Row.BackColor = Color.Yellow;
                        e.Row.ForeColor = Color.Black;
                        break;
                    case -3: e.Row.BackColor = Color.LightSalmon;
                        e.Row.ForeColor = Color.Black;
                        break;
                    case -4: e.Row.BackColor = Color.Tomato;
                        e.Row.ForeColor = Color.White;
                        break;
                }
 
                if (dayDiff < -4)
                {
                    e.Row.BackColor = Color.Red;
                    e.Row.ForeColor = Color.White;
                }
 
                if (dayDiff > 0)
                {
                    e.Row.BackColor = Color.Green;
                    e.Row.ForeColor = Color.Yellow;
                }
            }
        }
 
        
        protected void GridView_NewLeadRequesedCallBacks_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DateTime serverTime = DateTime.Now;
                Int32 dayDiff = Convert.ToDateTime(e.Row.Cells[3].Text).Subtract(serverTime).Days;
 
                switch (dayDiff)
                {
                    case -1: e.Row.BackColor = Color.LightYellow;
                        e.Row.ForeColor = Color.Black;
                        break;
                    case -2: e.Row.BackColor = Color.Yellow;
                        e.Row.ForeColor = Color.Black;
                        break;
                    case -3: e.Row.BackColor = Color.LightSalmon;
                        e.Row.ForeColor = Color.Black;
                        break;
                    case -4: e.Row.BackColor = Color.Tomato;
                        e.Row.ForeColor = Color.White;
                        break;
                }
 
                if (dayDiff < -4)
                {
                    e.Row.BackColor = Color.Red;
                    e.Row.ForeColor = Color.White;
                }
 
                if (dayDiff > 0)
                {
                    e.Row.BackColor = Color.Green;
                    e.Row.ForeColor = Color.Yellow;
                }
            }
        }
 
        protected void FindLoggedInAgent()
        {
            string strUser, strPass;
 
            Session["AgentLoggedIn"] = 0;
 
            if ((Request.QueryString["1"] != null) && (Request.QueryString["2"] != null))
            {
                strUser = Request.QueryString["1"].ToString();
                strPass = Request.QueryString["2"].ToString();    
 
                Session["fortuneBaseURLSuffix"] = "?1=" + strUser + "&2=" + strPass;
 
                SqlDataSource FORTUNESQLDataSource = new SqlDataSource();
                FORTUNESQLDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["FORTUNEConnectionString"].ToString();
 
                string sqlSTR = "SELECT [StaffMember_ID], [CompanyAgent_ID] FROM [StaffMember] WHERE [ASPnetUserName]='" + strUser + "' AND [ASPnetPassword]='" + strPass + "'";
 
                using (SqlConnection FORTUNEConnection1 = new SqlConnection(FORTUNESQLDataSource.ConnectionString))
                {
                    FORTUNEConnection1.Open();
                    SqlCommand scCommand = new SqlCommand(sqlSTR, FORTUNEConnection1);
 
                    IDataReader rdr = null;
                    try
                    {
                        rdr = scCommand.ExecuteReader();
                        while (rdr.Read())
                        {
                            if (rdr[0] != DBNull.Value)
                                Session["fortuneAgent_ID"] = (int)rdr[0];
 
                            if (rdr[1] != DBNull.Value)
                                Session["fortuneAgency_ID"] = (int)rdr[1];
 
                            Session["AgentLoggedIn"] = 1;
                        }
                    }
                    catch (Exception ex)
                    {
                        dbu.SQL_FailureHandler(ex);
                    }
                    finally
                    {
                        FORTUNEConnection1.Close();
                        if (rdr != null)
                        {
                            rdr.Close();
                            rdr.Dispose();
                        }
                    }
                }
            //}
 
            if ((int)Session["AgentLoggedIn"] != 1)
                Response.Redirect((string)Session["fortuneBaseURL"] + "/Login.aspx", true);
        }
 
        private void UpdateCCClientCaseRecord()
        {
            SqlDataSource FORTUNESQLDataSource = new SqlDataSource();
 
            FORTUNESQLDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["FORTUNEConnectionString"].ToString();
 
            System.Data.SqlClient.SqlCommand scCommand = new System.Data.SqlClient.SqlCommand();
            scCommand.CommandType = System.Data.CommandType.StoredProcedure;
            scCommand.CommandText = "BackOffice.UpdateClientCaseInStaffMember";
            scCommand.Parameters.Add("@RETURN_VALUE", System.Data.SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
 
            SqlConnection FORTUNEConnection1 = new SqlConnection(FORTUNESQLDataSource.ConnectionString);
 
            scCommand.Parameters.AddWithValue("@StaffMember_ID", (int)Session["fortuneAgent_ID"]);
            scCommand.Parameters.AddWithValue("@CCMasterAccount_ID", (int)Session["CCMasterAccount_ID"]);
            scCommand.Parameters.AddWithValue("@CCClientCase_ID", (int)Session["CCClientCase_ID"]);
 
            try
            {
                FORTUNEConnection1.Open();
                scCommand.Connection = FORTUNEConnection1;
                scCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                dbu.SQL_FailureHandler(ex);
            }
            finally
            {
                FORTUNEConnection1.Close();
            }
        }        
    }
}

Open in new window

add server side buuton in place of

<button type="button" OnClick="javascript:window.location = 'http://CaseTracking';">View</button>

like..

<asp:Button ID="ButtonView" runat="server" CommandName="ViewCommand" Text="View />

and check CommandName  in GridView_SellToProspect_RowCommand event
like...

protected void GridView_SellToProspect_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "ViewCommand")
            {
                    // do
            }
        }

I need to use this button type:  <button type="button" OnClick="javascript:window.location = 'http://CaseTracking';">View</button>


otherwise I cannot pass a feedback to the container window (winform)....i.e. the winform is checking the navigating of the web-page... and this seems to be onyl trappable via a javascript routine as above.
ASKER CERTIFIED SOLUTION
Avatar of Binuth
Binuth
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial