Click here to Skip to main content
15,917,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi experts,
plz help me its very essential for me,god bless you,im open for every suggestion
i have a gridview with 3 cell,in cell 3 i have a button i want when user clicks on button in click function i access to selected row and a data that has been bind to gridview but it didnt show in cells i have to read it from data bind to gridview or say if i use linqdatasource how can i access to selected row.
i want do it without object data source because i use linq to sql :

Thanks in advance for an answer.
C#
protected void btnShowData(object sender, EventArgs e)
    {

        BLL.Posts.FillPosts(MyWebApplication.Sessions.AuthenticatedUser.UserID);

        Button btnShow = (Button)sender;

         if (linqDatasource != null)
        {
          ...?
            //  myRich.LoadContent(strTitle, strBody);

        }
Posted
Updated 14-Dec-11 1:44am
v2
Comments
Sergey Alexandrovich Kryukov 19-Feb-13 0:16am    
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

YourDatagridview.SelectedCells will not work???!
 
Share this answer
 
SelectedRow[^] should give you the answer.
 
Share this answer
 
Hi

Try the following code

C#
protected void btnShowData(object sender, EventArgs e)
    {

        BLL.Posts.FillPosts(MyWebApplication.Sessions.AuthenticatedUser.UserID);

        Button btnShow = (Button)sender;
        TableRow row = (TableRow)btnShow .Parent.Parent;//gives you the selected row
         if (linqDatasource != null)
        {
          ...?
            //  myRich.LoadContent(strTitle, strBody);

        }
}.



Hope this helps
 
Share this answer
 
Hi ,

you can use Row_command Event of Grid view for get GridView Row index.

at Aspx page Side UI.

ASP.NET
<asp:gridview id="GridView1" runat="server" onrowcommand="GridView1_RowCommand" xmlns:asp="#unknown">
     <columns>
      <asp:templatefield headertext="Select">
       <itemtemplate>
            <asp:button id="btnSelect">CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CommandName="Select" />
        </asp:button></itemtemplate>
      </asp:templatefield>
     </columns>
</asp:gridview>

in .cs file
C#
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
// Get Row index
            int intRowid = Convert.ToInt16(e.CommandArgument);

//Get Row
            GridViewRow GrdRow = GridView1.Rows[intRowid];
        // Write your code
        }

    }
 
Share this answer
 

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