Solved

Gridview User Control event not firing

Posted on 2016-10-11
4
93 Views
Last Modified: 2016-10-13
I have a gridview user control that does everything I need it to except for one thing. I can NOT get the SelectedIndexChanged or Changing events to fire. I have put it in the user control but still cannot get it to fire so that I can use it for my needs. I do have this code on RowDataBound

'e.Row.Attributes("onclick") = Page.ClientScript.GetPostBackClientHyperlink(myGridview, e.Row.Cells(7).Text & "|" & e.Row.Cells(5).Text & "|" & e.Row.Cells(8).Text)
            'e.Row.ToolTip = "Click to select this row."

Open in new window

and my markup code is
   <asp:GridView ID="gvGeneric" runat="server" AutoGenerateColumns="false" AllowPaging="true"
        AllowSorting="True" SelectedIndex="0"
        OnSorting="GridView_Sorting" 
        OnRowDataBound="GridView_RowDataBound" 
        OnDataBound="GridView_DataBound" 
        OnRowDeleting="GridView_RowDeleting"        
        OnRowEditing="GridView_RowEditing" 
        OnRowUpdating="GridView_RowUpdating"
        OnRowCancelingEdit="GridView_RowCancelingEdit"  
        OnSelectedIndexChanged="GridView_SelectedIndexChanged"
        OnSelectedIndexChanging="GridView_SelectedIndexChanging"
        PagerSettings-Visible="false" Width="95%">
       
        <RowStyle HorizontalAlign="Center" Height="25px" CssClass="hover_row" />
        <AlternatingRowStyle HorizontalAlign="Center" CssClass="hover_row"/>
        <EditRowStyle cssClass="GridViewEditRow" />

        <EmptyDataRowStyle Height="40px" HorizontalAlign="Center" />
        <EmptyDataTemplate>
            <b>No Data Found</b>
        </EmptyDataTemplate>

    </asp:GridView>

Open in new window


I wanted to mention the RowDataBound but Im not sure if that is going to help anyone fix my issue but thought I would mention it anyway.
If anyone needs anymore info please ask.
Thanks in advance...
0
Comment
Question by:jknj72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 41839700
from MSDN....
The SelectedIndexChanged event is raised when a row's Select button is clicked, but after the GridView control handles the select operation. This enables you to ...

and you dont have
autogenerateselectbutton="True"

Open in new window

so the select button never shows up.

also can create your own Select button in any location...
<asp:buttonfield buttontype="Button"
                CommandName="Select"
                 headertext="Select Item"
                 text="Your Custom Text"/>

i add my own buttons in cells and trap those clicks.
0
 

Author Comment

by:jknj72
ID: 41840088
Im what event are you trapping the clicks? Are you using the RowCommand event? Thanks for your help!
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 41840203
snip from my app...  I use a commandfield as the first column.. this triggers the SelectedIndexChanged event.

        <asp:GridView ID="GridViewProjList" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" DataSourceID="ODS_Projects" 
            onselectedindexchanged="GridViewProjList_SelectedIndexChanged" 
            HorizontalAlign="Center" style="text-align: center">
            <Columns>
                <asp:CommandField ButtonType="Image" SelectText="--&gt;" 
                    ShowSelectButton="True" SelectImageUrl="~/images/pick-r.png" />

Open in new window

.

    protected void GridViewProjList_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Get the currently selected row using the SelectedRow property.
        GridViewRow row = GridViewProjList.SelectedRow;

        // Display the company name from the selected row.
        // zero based columns
        //MessageLabel.Text = "You selected " + row.Cells[2].Text + ".";
        string ProjId = row.Cells[1].Text;

Open in new window



in another area, i use a Hyperlink field to create a link to details page. no Select button.

protected void GridViewProjDocs_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // determine the value of the Hyperlink field
            HyperLink hlDocId = ((HyperLink)e.Row.FindControl("HyperLinkDocId"));
            Label filelinks = (Label)e.Row.FindControl("LabelFileLinks");
            Label Title = (Label)e.Row.FindControl("lblTitle");
            
            CheckBoxList chkFiles = (CheckBoxList)e.Row.FindControl("cklstFiles");

            DataRowView row = (DataRowView)e.Row.DataItem;

            //build the link to Document details page
            hlDocId.NavigateUrl = String.Format("details_prjdoc.aspx?DocNo={0}", row["DocNo"]);
            hlDocId.Text = row["DocId"].ToString();

Open in new window

0
 

Author Closing Comment

by:jknj72
ID: 41841977
thank you for your help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

761 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