Get row data of a GridView

Hi... I have a GridView. It contains a button as a button column. My requirement is when I select any button in a particular row the data in that particular row should be retrieved and should be added to another gridview. How can I achieve it.Any body Help me out.....

Thanks in advance 

 

0
mrkk
3/25/2008 4:30:06 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
800 Views

Similar Articles

[PageSpeed] 37

Hi

Please go through this below link

http://forums.asp.net/t/1234057.aspx 

This also talks same 


Thanks
~Avinash desai~
Software Developer
Bangalore

Please remember to click "Mark as Answer" on this post if it helped you.
0
Avinash
3/25/2008 5:33:10 AM

mrkk:

Hi... I have a GridView. It contains a button as a button column. My requirement is when I select any button in a particular row the data in that particular row should be retrieved and should be added to another gridview. How can I achieve it.Any body Help me out.....

Thanks in advance


Hi mrkk,

First give your Button Column a CommandName and try this snippet below on GridView1_RowCommand event

C# 

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "SELECT") {
        LinkButton lb = (LinkButton)sender;
        GridViewRow row = (GridViewRow)lb.NamingContainer;
        if (row != null) {
           
           
            string str = GridView1.Rows(row.RowIndex).Cells(1).Text;
            Response.Write(str);
           
        }
    }

VB.NET

Protected Sub GridView1_RowCommand1(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
    If e.CommandName = "SELECT" Then
        Dim lb As LinkButton = DirectCast(sender, LinkButton)
        Dim row As GridViewRow = DirectCast(lb.NamingContainer, GridViewRow)
        If row IsNot Nothing Then


            Dim str As String = GridView1.Rows(row.RowIndex).Cells(1).Text
            Response.Write(str)
           
        End If
    End If
End Sub 

 

Regards,

Vinz
 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
3/25/2008 6:27:09 AM

 Another way arround is using the Built-in SelectCommad Field in your Grid

<asp:GridView ID="GridView1"  runat="server" ShowFooter="true" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"  >
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField   />
<asp:BoundField   />
</Columns>
</asp:GridView>

So on SelectedIdexChange you have something like

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
       for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.SelectedIndex == i)
            {
               string str = GridView1.Rows[i].Cells[1].Text;
            }
       }
    }


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
3/25/2008 6:31:51 AM
Reply:

Similar Artilces:

Data Controls insert rows into gridview then insert rows from gridview into SQL Table
Hello there, I'm still new at performing miracles with code . Currently I am having trouble with my latest coding adventure I have a web application which records jobs and labour assigned to jobs. The issue in particular I'm having is the way in which labour is to be assigned. I want to use standard controls (Textbox, Dropdownlist) to record the values into a gridview (ie,put multiple rows into the gridview using the controls). Then, when all the inserting is complete, the user clicks a submit button to insert all the rows from the gridview into a database table. The reason for...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once?
 Hi Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once onto the grid? What I mean is some grid that 's as flexible as MS Excel grid for example.  Any suggestions will be very much appreciated.E The Repeater control is a highly customisable data presentation controlRohin.NET developerNever trust a computer you can't throw out a window. - Steve WozniakPlease remember to click on 'Mark as answer', if this post helped you......

How to get row selected in Gridview and then to get the data from the cells in that Grid?
I have a gridview with about 30 rows of data. If someone selects a row in the grid(Clicking or double clicking) then I want to get the values in each column/cell in that row. Once I get those values, I want to populate other edit controls on my web form with the values selected from the row. So the big question here, is how to capture the row selected from clicking or double clicking. Then how to get the column cell items?   Clickable GridView Row http://www.codeproject.com/aspnet/DoubleClickGridviewRow.asphttp://www.gridviewguy.com/ArticleDetails.aspx?articleID=188http://aspadvice....

Getting Information from the Controls (TemplateField or BoundField ) from any of the Data Presentation Controls
Hello Everybody,I have a very important question for me.For example, I have a GridView.It has three BoundFields and one TemplateFieldI want to get information from any of the record (row,line etc ) using any of the BoundFields or TemplateFields.And also I want to accomplish this not only with GridView but also other Data Presentation Controls, DetailsView FormView and Repeater.Shortly, Can anybody help me how to refer Controls in GridView, FormView, DetailsView, RepeaterPS: I have searched in Google and many sites,forums. But I couldn't see any solution and see that many people ask the same ...

How to get the data of a particular row in gridview without editing that row.
I have a gridview in a page in that ihave hyperlink as one column on click of that i want to go next page with the data present in that corresponding row. How shell i read the data from grid view for that pirticular row.On which event i can get the data. HI, the row that is selected should be passed into a string or an array or in sessionsthis can be done through this code  protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)    {        Label _lbl = new Label();      &...

How to delete row from GridView control
Hello,  I am working on an ASP.NET 2.0 app, and I am trying to wire up a "Delete" button to a gridview control on a form. Here is the code for the ASP :  <asp:GridView ID="gvInConditions" runat="server" AutoGenerateColumns="true" OnRowDeleting="gvInConditions_RowDeleting" DataKeyNames="Condition_ID" >         <Columns>                <asp:CommandField ButtonType="Button" SelectText=&...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Bind Data to an Image Control not in a Data Presentation Control
I've been searching for two days but I don't really know what to search for.I'm making a site for a photographer.  The Default.aspx page displays Albums by showing a title, image and description from the database table Albums. Click an album to view the contents and it passes the QueryString which is AlbumName.  The ViewAlbum.aspx page uses the QueryString to display an UpdatePanel holding a Large Image and a Repeater full of dynamically filled ImageButtons for thumbs.  Both are from the database table Photos and are retrieved using an ObjectDataSource. Click the ...

Getting control data from GridView
 How can I get data from a control placed in specific cell of a GridView???? Someone told me to use GridView.Row[pos].Cell[pos].Control[pos]... but it didn't work (out of index said)...  I don't know exactly what means GridView.Row[pos].Cell[pos].Control[pos].... can anybody help me???? Hi lmteijon,  You can do it this way in the RowDataBound event: Label lblCity = (Label)e.Row.Cells[2].FindControl("IDofTheControl"); or else in the following way after binding: GridView1.DataSource = dsCustomers.Tables[0]; GridView1.DataBind();foreach(GridVie...

how to get data from GridView control
Hi guys.  I have question  about retrieving data from GridView. In my project there is GridView which is representing data form some ObjectDataSource ( ObjectDataSource1 ) This ObjectDataSource1 returns from data base  table of ID and Title. Then I'm populating GridView with titles I'd changed Field for buttons. CommandName: Select  DataTextField : Title  This  allows me to "Click" on title and fire GridView1_SelectedIndexChanged event And when this event is fired I'd like to get ID. I hope my post isn't t...

Get GridView row data before Deleting
Hi  I have a gridview with enabled Deleting option.i want to get all the information of the Row being deleted. Any idea?  Thanks Are you doing this so you can undo your deletes?  How do you want to delete the records - do you have a deleted flag in your table so that the record won't show in your view or are you really want to delete the records for ever and ever?  Do you want to store the most recent delete in memory so you can add it back?  In that case, store it in class-level variables in the Row_Deleting event.  Actually you could declare those...

Getting data from a selected row in a gridview
I have created a webpage that has a gridview on it.  It has the following format; TagName       Value SCB_SV1      2.345SCB_SV2      3.345 What I would like to do is place Lables/Textboxs on a form that has a background image of two pumps.  It would look something like this;   SCADA WEBPAGE    lable1{2.345}         Pump#1{graphic}                   ...

Web resources about - Get row data of a GridView - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/6/2016 1:59:54 AM