Solved

datagridview

Posted on 2008-09-29
5
1,919 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:amillyard
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:Binuth
ID: 22602641
can u post full .aspx code?
0
 

Author Comment

by:amillyard
ID: 22603296
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

0
 
LVL 14

Expert Comment

by:Binuth
ID: 22603652
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
            }
        }

0
 

Author Comment

by:amillyard
ID: 22603724
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.
0
 
LVL 14

Accepted Solution

by:
Binuth earned 500 total points
ID: 22603793

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

i think it's not possible , b'coz when you click the button it will call clientOnClick event and redirect window location to http://CaseTracking'; , so never call the current page's event.

you can do alternative , use server side button(as per last comment)  and onRowCommand Event (GridView_SellToProspect_RowCommand) redirect to http://CaseTracking

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now