Help with GridView

Joined
Jan 22, 2009
Messages
2
Reaction score
0
Hello,

Im new to asp.net and am having a hard time figuring out how to have my GridView load a new page with a variable for an sql query..


To elaborate I have a GridView which lists off all companies in the database, I want to be able to allow the user to doubleclick on any of the rows then have it change pages to display all tickets opened by that company ID.

So far I have the GridView displaying all the companies, I have the javascript in place for the OnDblClick event.. But I don't know how to tie that into loading a new page with the CompanyID variable for that row intact.

Below is the gridview

Code:
<asp:Content ID="Content3" ContentPlaceHolderID="Main" Runat="Server">
    <table border="0" cellspacing="0" cellpadding="2" width="100%">
        <tr>
		    <td class="TitleCell">
		        <b><span class="s1">SNA ACCOUNT LIST</span></b>
		    </td>
	    </tr>
	    <tr>
	        <td>.</td>
	    </tr>
		<tr>
		    <td>    
        <asp:GridView ID="SnaAccountGridView" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" 
            DataSourceID="SnaHipReviewDataSource" BackColor="#CDD7A5" CellPadding="3" 
            OnRowDataBound="SnaAccountGridView_RowDataBound"
            CellSpacing="1" Font-Names="Arial,sans-serif" Font-Size="10pt" HorizontalAlign="Left" 
            PageSize="20" Width="750px">
            <RowStyle HorizontalAlign="Left" />
            <Columns>
                <asp:BoundField DataField="CompID" HeaderText="ID" 
                    SortExpression="CompID" HeaderStyle-Wrap="False" />
                <asp:BoundField DataField="Company" HeaderText="Company" 
                    SortExpression="Company" />
                <asp:BoundField DataField="Classification" HeaderText="Classification" 
                    SortExpression="Classification" HeaderStyle-Wrap="False" />
                <asp:BoundField DataField="PM" HeaderText="PM" SortExpression="PM" HeaderStyle-Wrap="False" />
                <asp:BoundField DataField="Status" HeaderText="Status" 
                    SortExpression="Status" HeaderStyle-Wrap="False" />
                <asp:BoundField DataField="CARE_LEVEL" HeaderText="Care Level" 
                    SortExpression="CARE_LEVEL" HeaderStyle-Wrap="False" />
                <asp:BoundField DataField="Region" HeaderText="Region" 
                    SortExpression="Region" HeaderStyle-Wrap="False" />
            </Columns>
            <HeaderStyle BackColor="#95A84A" />
            <AlternatingRowStyle BackColor="White" Font-Names="SansSerif" />
        </asp:GridView>

        <asp:SqlDataSource ID="SnaHipReviewDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SNA_TRTTestConnectionString %>" 
            SelectCommand="SELECT * FROM [SNA_Parent_Accounts]"></asp:SqlDataSource>
    
            </td>
		</tr>
    </table>
</asp:Content>


And here is the CodeBehind

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SnaAccountView : System.Web.UI.Page
{
    protected void SnaAccountGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Alternate)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#EBEDE9'; this.style.cursor='hand';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';");
                e.Row.Attributes.Add("onDblClick",
                    this.GetPostBackClientEvent(SnaAccountGridView, 
                    "Select$" + e.Row.RowIndex.ToString()));
            }
            else
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#EBEDE9'; this.style.cursor='hand';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#CDD7A5';");
                e.Row.Attributes.Add("onDblClick",
                    this.GetPostBackClientEvent(SnaAccountGridView,
                    "Select$" + e.Row.RowIndex.ToString()));
            }
        }

    }

}


Would the GetPostBackClientEvent be the best approach on the dblclick event? If not what would be a better/simplier method?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top