Click here to Skip to main content
15,883,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to select the grid selected row values, in clickevent not firing. can any one helps me
or suggest any other code.


protected void grdTimeSheetEntry_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            //string company = GridView1.SelectedRow.Cells[0].Text;
            GridViewRow row = grdTimeSheetEntry.SelectedRow;
            string c1 = row.Cells[2].Text;
            string c2 = row.Cells[3].Text;
            string c3 = row.Cells[4].Text;
            string c4 = row.Cells[5].Text;
        }
    }

<asp:GridView ID="grdTimeSheetEntry" runat="server" BackColor="White" BorderColor="#3366CC"
            BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="100%" 
                AllowPaging="True" onpageindexchanging="grdTimeSheetEntry_PageIndexChanging" 
                onselectedindexchanging="grdTimeSheetEntry_SelectedIndexChanging" 
                PageSize="15" onpageindexchanged="grdTimeSheetEntry_PageIndexChanged" 
               
                onrowcommand="grdTimeSheetEntry_RowCommand" 
                onselectedindexchanged="grdTimeSheetEntry_SelectedIndexChanged" 
                AutoGenerateColumns="False">
            <RowStyle BackColor="White" ForeColor="#003399" />
            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
            <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
            <Columns>
               <asp:BoundField DataField="EntryTypeName" Visible="true" ></asp:BoundField>
               <asp:BoundField DataField="ProductName" Visible="true" ></asp:BoundField>
               <asp:BoundField DataField="VersionNumber" Visible="true" ></asp:BoundField>
               <asp:BoundField DataField="BugID" Visible="true" ></asp:BoundField>
               <asp:BoundField DataField="SupportID" Visible="true" ></asp:BoundField>
               <asp:BoundField DataField="Description" Visible="true" ></asp:BoundField>
               <asp:BoundField DataField="Date" Visible="true" ></asp:BoundField>
               <asp:BoundField DataField="Effort" Visible="true" ></asp:BoundField>
            </Columns>
        </asp:GridView>
Posted
Updated 8-Jul-13 21:35pm
v4
Comments
Siddhesh Patankar 9-Jul-13 2:34am    
while debugging is it entering the event.. try putting a breakpoint and check if it is entering the event... I will answer based on that
kesav prakash 9-Jul-13 2:55am    
break point not hitting sir
Samresh.ss 9-Jul-13 3:04am    
You need a commandfield to have event raised.
refer: http://www.codeproject.com/Questions/510755/GridViewplusSelectedindexplusChangedplusEventplusn
Have you defined the event in GridView mark up in aspx page?
kesav prakash 9-Jul-13 3:36am    
kindly view my desgign page and reply me

Try This:

C#
protected void grdTimeSheetEntry_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            //string company = GridView1.SelectedRow.Cells[0].Text;
            GridViewRow row = grdTimeSheetEntry.SelectedRow;
            DropDownList ddl1 = row.FindControl("[your dropdown ID here]");
            DropDownList ddl2 = row.FindControl("[your dropdown ID here]");
            DropDownList ddl3 = row.FindControl("[your dropdown ID here]");
            DropDownList ddl4 = row.FindControl("[your dropdown ID here]");  
            string c1 = ddl1.Text;
            string c2 = ddl2.Text;
            string c3 = ddl3.Text;
            string c4 = ddl4.Text;
        }
    }


I think it is a wrong event in which you are writing the code. Try writing it in the Dropdownlist selectedindexchanged event. Just check if above code achieves what you want else I will tell you how to do in dropdownlist selectedindexchanged event.
 
Share this answer
 
Comments
kesav prakash 9-Jul-13 2:53am    
actually my task is there is a datagrid with 4coloumn. if i select any particular row cell i need all the 4 value from that row.
Siddhesh Patankar 9-Jul-13 3:04am    
Can you please add your .aspx page or the gridview from that page using Improve Question. I need to see the design to suggest an answer
kesav prakash 9-Jul-13 3:37am    
i added my desginpage code
Try these.

GridView.SelectedRow Property[^]
How to get cell value of gridview using JQUERY[^]

Accept as answer if solve you problem.
 
Share this answer
 
v2
Only clicking on the Row will not fire the event. You have to have a Button on the row to handle this.

You can do that by adding the below aproperty in the GridView Mark up in aspx page.
AutoGenerateSelectButton="True"

Without the button, you can also do that.
For that try with the below code inside RowDataBound Event
C#
protected void grdTimeSheetEntry_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.grdTimeSheetEntry, "Select$" + e.Row.RowIndex);
    }
} 

Declare that in GridView Mark up as well.
 
Share this answer
 
v2
Comments
kesav prakash 9-Jul-13 7:51am    
i have retrived the values all these values. i need to show it in one panel popup in grid clickevent. but the popup came for a sec and disappears may i know whats the problem
but inside the panel textboxes all got its values
Do one thing. Add another question with the code, which you are using to open the popup.

Thanks,
Tadit
kesav prakash 9-Jul-13 8:07am    
AJAX popup (popuping panel)in ASP.net Disappers in a sec i posted as new question kindly help me
Ok. I will try. :)
kesav prakash 10-Jul-13 9:36am    
how to get the datagridview selected cell value(text) without using the row.cell[index]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900