Solved

C# Dataview Template button 2.0

Posted on 2009-03-31
23
1,196 Views
Last Modified: 2013-12-17
Good day

I have a Asp.net VS2008 on .net 2.0 where I have 3 dataviews each data view contains a view button, when the view button is clicked, I need to catch the value of column[0] in die dataview, the redirect to a 2nd form  passing the value from the column[0] to the second page.
How do i  Catch the click event on the button and get the value from column[0]?

Click on the button and I get:

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Thanx
Phillip
HTML 
 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 

<!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 runat="server">

    <title></title>

    <pages validateRequest="false" enableEventValidation="false" /> 

</head>

<body>

    <form id="form1" runat="server">

    <asp:GridView ID="GridView3" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        

        

        style="z-index: 1; left: 342px; top: 441px; position: absolute; height: 133px; width: 322px" 

        AutoGenerateColumns="False">

         <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:TemplateField HeaderText="View">

                <ItemTemplate>

                    <asp:Button ID="View" runat="server" CommandName="Edit" Text="View" 

                        onclick="View_Click" />

                </ItemTemplate>

            </asp:TemplateField>

        </Columns>

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#CCFF66" Font-Bold="True" ForeColor="Black" 

             BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

             VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    <asp:GridView ID="GridView1" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        

        

        style="z-index: 1; left: 678px; top: 440px; position: absolute; height: 133px; width: 322px" 

        AutoGenerateColumns="False">

         <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:TemplateField HeaderText="View">

                <ItemTemplate>

                    <asp:Button ID="View" runat="server" CommandName="Edit" Text="View" 

                        onclick="View_Click" />

                </ItemTemplate>

            </asp:TemplateField>

        </Columns>

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#9933FF" Font-Bold="True" ForeColor="White" 

             BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

             VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/FIFA-HIRAC.png" 

        

        

        style="z-index: 1; left: 309px; top: 27px; position: absolute; height: 396px; width: 875px;" />

    <p>

    <asp:GridView ID="GridView2" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        

        style="z-index: 1; left: 7px; top: 440px; position: absolute; height: 133px; width: 324px" 

        AutoGenerateColumns="False" 

        onselectedindexchanged="GridView2_SelectedIndexChanged">

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:TemplateField HeaderText="View">

                <ItemTemplate>

                    <asp:Button ID="View" runat="server" CommandArgument="Edit" CommandName="Edit" 

                        onclick="View_Click" Text="View" />

                </ItemTemplate>

            </asp:TemplateField>

        </Columns>

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#0066FF" Font-Bold="True" ForeColor="White" 

            BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

            VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    </p>

    </form>

</body>

</html>
 
 

C#
 

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.Sql;

using System.Data;

using System.Data.SqlClient;
 

public partial class _Default : System.Web.UI.Page 

{

    protected void Page_Load(object sender, EventArgs e)

    {

        FillDG(GridView2,1);

        FillDG(GridView1,2);

        FillDG(GridView3,3);

        
 

    }

   

    private void FillDG(GridView MyGrid, int Group)

    {

        DataTable dt = new DataTable("Fault Info");

        dt.Columns.Add("Province", System.Type.GetType("System.String"));

        dt.Columns.Add("TestOk", System.Type.GetType("System.String"));

        dt.Columns.Add("Faulty", System.Type.GetType("System.String"));

        object[] x = new object[3];

        if (Group == 1)

        {

            x[0] = "Eastern Cape";

            x[1] = "10";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "15";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "12";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "7";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "6";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "16";

            x[2] = "2";

            dt.Rows.Add(x);

        }

        else if (Group == 2)

        {

            x[0] = "Eastern Cape";

            x[1] = "15";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "10";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "20";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "18";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "12";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "10";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "11";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "9";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "22";

            x[2] = "0";

            dt.Rows.Add(x);

        }

        else

        {

            x[0] = "Eastern Cape";

            x[1] = "10";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "8";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "15";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "12";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "8";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "7";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "6";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "16";

            x[2] = "5";

            dt.Rows.Add(x);

        }

        MyGrid.DataSource = dt;

        MyGrid.DataBind();
 
 

        foreach (GridViewRow row in MyGrid.Rows)

        {

            

            Int32 intValue = Convert.ToInt32(row.Cells[2].Text);

            if (intValue == 1)

            {

                row.Cells[2].BackColor = System.Drawing.Color.LightCoral;

            }

            else if (intValue == 2)

            {

                row.Cells[2].BackColor = System.Drawing.Color.Coral;

            }

            else if (intValue == 5)

            {

                row.Cells[2].BackColor = System.Drawing.Color.Red;

            }

            else if (intValue >= 4)

            {

                row.Cells[2].BackColor = System.Drawing.Color.DarkRed;

            }

        }

    }

}

Open in new window

0
Comment
Question by:vemmenpc
  • 12
  • 8
23 Comments
 
LVL 8

Expert Comment

by:arhame
ID: 24029058
You'll want to set the e.commandarguement value. What this allows you to do is send a value (even a databound one) to your codebehind.

So on your button, you could have something similiar to this:


Code:
<?xml:namespace prefix = asp /> <asp:Button ID="View" runat="server" CommandName="Edit" CommandArgument='<%# Eval("ValueID") %>' Text="View"
                        onclick="View_Click" />


What that does, is give the e.commandarguement.tostring() the same value as the databound column ValueID (obviously put in your own databound column) of the button when you call it in the code behind.

So if you had in your codebehind:


Code:
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles GridView1.RowCommand
If e.CommandName = "Edit" Then
Response.Write(e.CommandArgument.ToString())
End If
End Sub

It would write whatever the value of the databound clumn is.
 
Let me know if you have any questions
0
 
LVL 8

Expert Comment

by:arhame
ID: 24029070
Ugh.... it made the first code sample ugly... here it is again without all that extra crap.  Last time I try to post in Rich Text mode here....


<asp:Button ID="View" runat="server" CommandName="Edit" CommandArgument='<%# Eval("ValueID") %>' Text="View" onclick="View_Click" />
0
 

Author Comment

by:vemmenpc
ID: 24036231
Hi
 I get  this error o  the HTML side:
'ASP.default_aspx' does not contain a definition for 'View_Click' and no extension method 'View_Click' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)
I inserted the code like this:

<asp:GridView ID="GridView2" runat="server" BackColor="White"
BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3"
GridLines="Vertical"

style="z-index: 1; left: 10px; top: 307px; position: absolute; height: 133px; width: 324px"
AutoGenerateColumns="False" >
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:BoundField HeaderText="Province" DataField="Province" />
<asp:BoundField HeaderText="Test OK" DataField="TestOk" />
<asp:BoundField HeaderText="Faulty" DataField="Faulty" />
<asp:TemplateField HeaderText="View">
<ItemTemplate>

<asp:Button ID="View" runat="server" CommandName="Edit" CommandArgument='<%# Eval("ValueID") %>' Text="View" onclick="View_Click" />
<asp:Button ID="Button2" runat="server" Text="Button" />

</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#0066FF" Font-Bold="True" ForeColor="White"
BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center"
VerticalAlign="Middle" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
Thanx for the help!

0
 

Author Comment

by:vemmenpc
ID: 24036235
<asp:GridView ID="GridView2" runat="server" BackColor="White"
        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3"
        GridLines="Vertical"
       
        style="z-index: 1; left: 10px; top: 307px; position: absolute; height: 133px; width: 324px"
        AutoGenerateColumns="False" >
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <Columns>
            <asp:BoundField HeaderText="Province" DataField="Province" />
            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />
            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />
            <asp:TemplateField HeaderText="View">
                <ItemTemplate>
                <asp:Button ID="View" runat="server" CommandName="Edit" CommandArgument='<%# Eval("ValueID") %>' Text="View" onclick="View_Click" />
                    <asp:Button ID="Button2" runat="server" Text="Button" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#0066FF" Font-Bold="True" ForeColor="White"
            BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center"
            VerticalAlign="Middle" />
        <AlternatingRowStyle BackColor="#DCDCDC" />
    </asp:GridView>
0
 

Author Comment

by:vemmenpc
ID: 24047595
arhame:
Can you do this in C# please.
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As    System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles GridView1.RowCommand
If e.CommandName = "Edit" Then
Response.Write(e.CommandArgument.ToString())
End If
End Sub

 
 
0
 
LVL 8

Expert Comment

by:arhame
ID: 24049443
Sorry for the slow response - I was out of town at a clients office all day yesterday and not behind my computer.  Here that is converted to C#

protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
    if (e.CommandName == "Edit") {
        Response.Write(e.CommandArgument.ToString());
    }
}

Also from the linkbutton remove the onclick="View_Click" - unless you've added something more to it since.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24054353
Keep in mind that all Response.write(e.CommandArguement.ToString()); is going to do is display the value on the page.  If you want to redirect to another page then you'd need to do something like this:

Response.Redirect("www.yourwebsite.com/yourpage.aspx?ID=" & e.CommandArguement.ToString)

That will put the value into a querystring that you can grab on the next page.
0
 

Author Comment

by:vemmenpc
ID: 24057610
This is not going well .... Now I get the... below error   Im tryin this on gridview2
Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.  

HTML:
 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">

    <title>FIFA</title>

    </head>

<body>

    <form id="form1" runat="server">

    <asp:GridView ID="GridView3" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        style="z-index: 1; left: 361px; top: 308px; position: absolute; height: 133px; width: 322px" 

        AutoGenerateColumns="False">

         <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:CommandField ShowSelectButton="True" />

        </Columns>

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#CCFF66" Font-Bold="True" ForeColor="Black" 

             BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

             VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    <asp:GridView ID="GridView1" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        style="z-index: 1; left: 713px; top: 309px; position: absolute; height: 133px; width: 322px" 

        AutoGenerateColumns="False">

         <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:CommandField ShowSelectButton="True" />

        </Columns>

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#9933FF" Font-Bold="True" ForeColor="White" 

             BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

             VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    <p>

    <asp:GridView ID="GridView2" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        style="z-index: 1; left: 10px; top: 307px; position: absolute; height: 133px; width: 324px" 

        AutoGenerateColumns="False" >

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:TemplateField HeaderText="View">

                <ItemTemplate>

                <asp:Button ID="View" runat="server" CommandName="Edit" CommandArgument='<%# Eval("Province") %>' Text="View"   />
 

               </ItemTemplate>

            </asp:TemplateField>

        </Columns>

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#0066FF" Font-Bold="True" ForeColor="White" 

            BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

            VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    </p>

    <p>&nbsp;</p>

    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 

        style="z-index: 1; left: 139px; top: 665px; position: absolute" Text="Button" />

    <p>&nbsp;</p>

    <asp:Image ID="Image1" runat="server" ImageUrl="~/FIFA-HIRAC.png" style="z-index: 1; left: 69px; top: 27px; position: absolute; height: 280px; width: 915px;" />

    </form>

</body>

</html>
 

C#:

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.Sql;

using System.Data;

using System.Data.SqlClient;
 

public partial class _Default : System.Web.UI.Page 

{

    protected void Page_Load(object sender, EventArgs e)

    {

        FillDG(GridView2,1);

        FillDG(GridView1,2);

        FillDG(GridView3,3);

    }

    private void FillDG(GridView MyGrid, int Group)

    {

        DataTable dt = new DataTable("Fault Info");

        dt.Columns.Add("Province", System.Type.GetType("System.String"));

        dt.Columns.Add("TestOk", System.Type.GetType("System.String"));

        dt.Columns.Add("Faulty", System.Type.GetType("System.String"));

        object[] x = new object[3];

        if (Group == 1)

        {

            x[0] = "Eastern Cape";

            x[1] = "10";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "15";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "12";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "7";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "6";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "16";

            x[2] = "2";

            dt.Rows.Add(x);

        }

        else if (Group == 2)

        {

            x[0] = "Eastern Cape";

            x[1] = "15";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "10";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "20";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "18";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "12";

            x[2] = "3";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "10";

            x[2] = "4";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "11";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "9";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "22";

            x[2] = "0";

            dt.Rows.Add(x);

        }

        else

        {

            x[0] = "Eastern Cape";

            x[1] = "10";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "8";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "15";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "12";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "8";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "7";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "6";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "16";

            x[2] = "5";

            dt.Rows.Add(x);

        }

        MyGrid.DataSource = dt;

        MyGrid.DataBind();

        

        foreach (GridViewRow row in MyGrid.Rows)

        {

           

            Int32 intValue = Convert.ToInt32(row.Cells[2].Text);

            if (intValue == 1)

            {

                row.Cells[2].BackColor = System.Drawing.Color.LightCoral;

            }

            else if (intValue == 2)

            {

                row.Cells[2].BackColor = System.Drawing.Color.Coral;

            }

            else if (intValue == 5)

            {

                row.Cells[2].BackColor = System.Drawing.Color.Red;

            }

            else if (intValue >= 4)

            {

                row.Cells[2].BackColor = System.Drawing.Color.DarkRed;

            }

        }

    }

    protected void GridView2_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)

    {

        if (e.CommandName == "Edit")

        {

            Response.Write(e.CommandArgument.ToString());

        }

    }
 

    

}

Open in new window

0
 

Author Comment

by:vemmenpc
ID: 24057913
I gor the previose error fixed,
now I get  The GridView 'GridView2' fired event RowEditing which wasn't handled.
0
 

Author Comment

by:vemmenpc
ID: 24058094
The previous error is now gone as well, but I still can't catch the click, I got a break on the C# event.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 8

Expert Comment

by:arhame
ID: 24059559
Try changing the CommandName="Edit" to CommandName="View".  Please post your current code again after you got rid of the last 2 errors.

Also we'll need to change the other code to:
protected void GridView2_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
        if (e.CommandName == "View")
        {
            Response.Write(e.CommandArgument.ToString());
        }
    }
0
 

Author Comment

by:vemmenpc
ID: 24065872
No, luck, I got a break point on the protected void GridView2_RowCommand , Code does not stop at the breakpoint
 
0
 

Author Comment

by:vemmenpc
ID: 24213596
Any help please?
0
 

Author Comment

by:vemmenpc
ID: 24223060
Please I need help on this.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24250735
Weird, for some reason it started putting the responses from you in my E-mail spam filter.

vemmenpc, one thing I want you to try is only populate the gridviews if the page isnot postback.  I have seen that cause quite a few issues when you databind each postback and then try to call events on what was posted.

If that doesn't fix the problem please update me with current code and what else you've tried.
protected void Page_Load(object sender, EventArgs e) 

{ 

    if (Page.IsPostback) { 

    } 

    else { 

        //Do Nothing, don't re-fill the datagrids 

        //Populate the data 

        FillDG(GridView2, 1); 

        FillDG(GridView1, 2); 

        FillDG(GridView3, 3); 

    } 

}

Open in new window

0
 
LVL 8

Expert Comment

by:arhame
ID: 24274370
Have you tried that vemmenpc?  Did you disappear like I did for a while?  Lol.
0
 

Author Comment

by:vemmenpc
ID: 24292483
I will try it today, and provide feedback within the next 5 hours. Was out of the office, went to a Cape Town office to load software.
 
 
0
 

Author Comment

by:vemmenpc
ID: 24292610
The only way I could catch the click event is with
protected void View_Click(object sender, EventArgs e)
{
Response.Write("666");
}
But How do I get the row information, this is with the IsPostback event added as per your previos sugestion. Will it be posabel to mail the project to you. vemmenpc @ telkom . co .za  I will zip the project.
 

HTML CODE

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">

    <title>FIFA</title>

    </head>

<body>

    <form id="form1" runat="server">

    <asp:GridView ID="GridView3" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        style="z-index: 1; left: 361px; top: 308px; position: absolute; height: 133px; width: 322px" 

        AutoGenerateColumns="False">

         <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:CommandField ShowSelectButton="True" />

        </Columns>

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#CCFF66" Font-Bold="True" ForeColor="Black" 

             BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

             VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    <asp:GridView ID="GridView1" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        style="z-index: 1; left: 713px; top: 309px; position: absolute; height: 133px; width: 322px" 

        AutoGenerateColumns="False">

         <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:CommandField ShowSelectButton="True" />

        </Columns>

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#9933FF" Font-Bold="True" ForeColor="White" 

             BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

             VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    <p>&nbsp;</p>

    <p>&nbsp;</p>

    <p>&nbsp;</p>

    <asp:Image ID="Image1" runat="server" ImageUrl="~/FIFA-HIRAC.png" style="z-index: 1; left: 69px; top: 27px; position: absolute; height: 280px; width: 915px;" />

    <asp:GridView ID="GridView2" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        style="z-index: 1; left: 10px; top: 307px; position: absolute; height: 133px; width: 324px" 

        AutoGenerateColumns="False" 

        onselectedindexchanged="GridView2_SelectedIndexChanged" >

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:TemplateField HeaderText="View">

                <ItemTemplate>

                <asp:Button ID="View" runat="server" CommandArgument='<%# Eval("Province") %>' 

                        Text="View"   PostBackUrl="~/Default.aspx" onclick="View_Click"   />

               </ItemTemplate>

            </asp:TemplateField>

        </Columns>

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#0066FF" Font-Bold="True" ForeColor="White" 

            BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

            VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    </form>

</body>

</html>
 

C# code
 

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.Sql;

using System.Data;

using System.Data.SqlClient;
 

public partial class _Default : System.Web.UI.Page 

{

    DataTable dt = new DataTable("Fault Info");

    protected void Page_Load(object sender, EventArgs e)

    {

        if (IsPostBack == false)

        {

            FillDG(GridView2, 1);

           // FillDG(GridView1,2);

           // FillDG(GridView3,3);

        }

    }

    private void FillDG(GridView MyGrid, int Group)

    {

        

        dt.Columns.Add("Province", System.Type.GetType("System.String"));

        dt.Columns.Add("TestOk", System.Type.GetType("System.String"));

        dt.Columns.Add("Faulty", System.Type.GetType("System.String"));

        object[] x = new object[3];

        if (Group == 1)

        {

            x[0] = "Eastern Cape";

            x[1] = "10";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "15";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "12";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "7";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "6";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "16";

            x[2] = "2";

            dt.Rows.Add(x);

        }

        else if (Group == 2)

        {

            x[0] = "Eastern Cape";

            x[1] = "15";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "10";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "20";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "18";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "12";

            x[2] = "3";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "10";

            x[2] = "4";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "11";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "9";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "22";

            x[2] = "0";

            dt.Rows.Add(x);

        }

        else

        {

            x[0] = "Eastern Cape";

            x[1] = "10";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "8";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "15";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "12";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "8";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "7";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "6";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "16";

            x[2] = "5";

            dt.Rows.Add(x);

        }

        MyGrid.DataSource = dt;

        MyGrid.DataBind();

        foreach (GridViewRow row in MyGrid.Rows)

        {

            Int32 intValue = Convert.ToInt32(row.Cells[2].Text);

            if (intValue == 1)

            {

                row.Cells[2].BackColor = System.Drawing.Color.LightCoral;

            }

            else if (intValue == 2)

            {

                row.Cells[2].BackColor = System.Drawing.Color.Coral;

            }

            else if (intValue == 5)

            {

                row.Cells[2].BackColor = System.Drawing.Color.Red;

            }

            else if (intValue >= 4)

            {

                row.Cells[2].BackColor = System.Drawing.Color.DarkRed;

            }

        }

    }

    private void view()

    {

        Response.Write("666");

    }

    protected void GridView2_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)

    {

        if (e.CommandName == "View")

        {

            Response.Write(e.CommandArgument.ToString());

        }

    }

    void GridView2_RowEditing(object sender, GridViewEditEventArgs e)

    {

        GridView1.EditIndex = e.NewEditIndex;

       // binddata();

    }

    void GridView2_RowDataBound(Object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            // Display the company name in italics.

            e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";

        }

    }

    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)

    {

                // Response.Write("666");

    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

       // Response.Write("666");

    }

    protected void View_Click(object sender, EventArgs e)

    {

        Response.Write("666");

    }

}

Open in new window

0
 
LVL 8

Accepted Solution

by:
arhame earned 295 total points
ID: 24295437
Here is working code.  I had to change a few things, like on the gridview add the OnRowCommand="Gridview2_RowCommand" event (so it knew to fire the event, that's why the break wasn't going off), had to add the RowCommand="View" to the button... and I think that's all maybe another thing... but anyways, heres working code:

:)


HTML Code:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" debug="true" %>

<!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>FIFA</title>

    </head>

<body>

    <form id="form1" runat="server">

    <asp:GridView ID="GridView3" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        style="z-index: 1; left: 361px; top: 308px; position: absolute; height: 133px; width: 322px" 

        AutoGenerateColumns="False">

         <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:CommandField ShowSelectButton="True" />

        </Columns>

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#CCFF66" Font-Bold="True" ForeColor="Black" 

             BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

             VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    <asp:GridView ID="GridView1" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        style="z-index: 1; left: 713px; top: 309px; position: absolute; height: 133px; width: 322px" 

        AutoGenerateColumns="False">

         <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:CommandField ShowSelectButton="True" />

        </Columns>

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#9933FF" Font-Bold="True" ForeColor="White" 

             BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

             VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    <p>&nbsp;</p>

    <p>&nbsp;</p>

    <p>&nbsp;</p>

    <asp:Image ID="Image1" runat="server" ImageUrl="~/FIFA-HIRAC.png" style="z-index: 1; left: 69px; top: 27px; position: absolute; height: 280px; width: 915px;" />

    <asp:GridView ID="GridView2" runat="server" BackColor="White" 

        BorderColor="Black" BorderStyle="Groove" BorderWidth="1px" CellPadding="3" 

        GridLines="Vertical" 

        style="z-index: 1; left: 10px; top: 307px; position: absolute; height: 133px; width: 324px" 

        AutoGenerateColumns="False" 

        onselectedindexchanged="GridView2_SelectedIndexChanged" OnRowCommand="GridView2_RowCommand" >

        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

        <Columns>

            <asp:BoundField HeaderText="Province" DataField="Province" />

            <asp:BoundField HeaderText="Test OK" DataField="TestOk" />

            <asp:BoundField HeaderText="Faulty" DataField="Faulty" />

            <asp:TemplateField HeaderText="View">

                <ItemTemplate>

                <asp:Button ID="View" runat="server" CommandArgument='<%# Eval("Province") %>' 

                        Text="View"   PostBackUrl="~/Default.aspx" CommandName="View"  />

               </ItemTemplate>

            </asp:TemplateField>

        </Columns>

        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

        <HeaderStyle BackColor="#0066FF" Font-Bold="True" ForeColor="White" 

            BorderColor="Black" BorderStyle="Groove" HorizontalAlign="Center" 

            VerticalAlign="Middle" />

        <AlternatingRowStyle BackColor="#DCDCDC" />

    </asp:GridView>

    </form>

</body>

</html>
 
 

C# Code:
 

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.Sql;

using System.Data;

using System.Data.SqlClient;
 

public partial class _Default : System.Web.UI.Page

{

    DataTable dt = new DataTable("Fault Info");

    protected void Page_Load(object sender, EventArgs e)

    {

        if (IsPostBack == false)

        {

            FillDG(GridView2, 1);

            // FillDG(GridView1,2);

            // FillDG(GridView3,3);

        }

    }

    private void FillDG(GridView MyGrid, int Group)

    {
 

        dt.Columns.Add("Province", System.Type.GetType("System.String"));

        dt.Columns.Add("TestOk", System.Type.GetType("System.String"));

        dt.Columns.Add("Faulty", System.Type.GetType("System.String"));

        object[] x = new object[3];

        if (Group == 1)

        {

            x[0] = "Eastern Cape";

            x[1] = "10";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "15";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "12";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "7";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "6";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "16";

            x[2] = "2";

            dt.Rows.Add(x);

        }

        else if (Group == 2)

        {

            x[0] = "Eastern Cape";

            x[1] = "15";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "10";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "20";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "18";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "12";

            x[2] = "3";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "10";

            x[2] = "4";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "11";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "9";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "22";

            x[2] = "0";

            dt.Rows.Add(x);

        }

        else

        {

            x[0] = "Eastern Cape";

            x[1] = "10";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Free State";

            x[1] = "8";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Gauteng";

            x[1] = "15";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "KwaZulu-Natal";

            x[1] = "12";

            x[2] = "2";

            dt.Rows.Add(x);
 

            x[0] = "Mpumalanga";

            x[1] = "8";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Limpopo Province";

            x[1] = "8";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "Northern Cape";

            x[1] = "7";

            x[2] = "0";

            dt.Rows.Add(x);
 

            x[0] = "North-West Province";

            x[1] = "6";

            x[2] = "1";

            dt.Rows.Add(x);
 

            x[0] = "Western Cape";

            x[1] = "16";

            x[2] = "5";

            dt.Rows.Add(x);

        }

        MyGrid.DataSource = dt;

        MyGrid.DataBind();

        foreach (GridViewRow row in MyGrid.Rows)

        {

            Int32 intValue = Convert.ToInt32(row.Cells[2].Text);

            if (intValue == 1)

            {

                row.Cells[2].BackColor = System.Drawing.Color.LightCoral;

            }

            else if (intValue == 2)

            {

                row.Cells[2].BackColor = System.Drawing.Color.Coral;

            }

            else if (intValue == 5)

            {

                row.Cells[2].BackColor = System.Drawing.Color.Red;

            }

            else if (intValue >= 4)

            {

                row.Cells[2].BackColor = System.Drawing.Color.DarkRed;

            }

        }

    }

    private void view()

    {
 
 

    }

    protected void GridView2_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)

    {

        if (e.CommandName == "View")

        {

            Response.Write(e.CommandArgument.ToString());

        }

    }

    void GridView2_RowEditing(object sender, GridViewEditEventArgs e)

    {

        GridView1.EditIndex = e.NewEditIndex;

        // binddata();

    }

    void GridView2_RowDataBound(Object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            // Display the company name in italics.

            e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";

        }

    }

    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)

    {

        // Response.Write("666");

    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

        // Response.Write("666");

    }
 

}

Open in new window

0
 

Author Closing Comment

by:vemmenpc
ID: 31564751
Hey, thanx for this response ant patience with me on this one, Im not sure if I struck a Blond moment with this one, but yes&
Phillip
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
cookies analysis tools 2 29
Round a string to two digits 12 25
Setting runtime form location 4 19
Birthdays 3 21
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…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

747 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

12 Experts available now in Live!

Get 1:1 Help Now