Retrieve row value for row with delete button?

Hello,

I am developing a simple ticket system and I can't figure out how to retrieve the value of a record that is not selected.  For example, I have a button in a gridview which changes the "Closed" value of that record from No, to Yes, which closes the ticket.  My problem is, I have searched and search and I can't find a way to find out what the value of the record that contains the clicked button.

This is my SQL statement:

 myCommand = New SqlCommand("Update Tickets Set Closed='Yes',ClosedDate='" & DateTime.Now & "' WHERE TicketID='" & GridView1.DataKeys(1).Values("TicketID") & "' ", conStr1)

The ( '1' ) is what I would like to change.  Do I need to add something to the event handler that will allow me to access the correct index?

Thank you greatly for any help you can provide,
Mark


 


Embrace the chaos, only with chaos will we ever see change.
0
Silverblade1486
9/19/2007 8:26:47 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
651 Views

Similar Articles

[PageSpeed] 22

In your RowDeleting event you have two arguments, the object sender and EventArgs e.  You should be able to get to the .RowIndex property of e.

Check the GridViewGuy:

http://www.gridviewguy.com/ArticleDetails.aspx?articleID=139

 


I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
Charles
9/19/2007 8:41:35 PM

 Unfortunately, I am not using the RowDeleting event, because I don't actually want to Delete the record.. just Update it.  I am currently using the click event of btnCloseTicket.  Any ideas how I can tell the buttons event what row it came from?

Thank you,
Mark
 


Embrace the chaos, only with chaos will we ever see change.
0
Silverblade1486
9/19/2007 8:44:15 PM

Well,the btnClick event still has sender and e, so see if you can cast sender to a row and then get the rowindex property off it, or see what properties are in your eventArgs.  There is a way, but its time for me to go pick up the kids, sorry.  I'll check in tomorrow.


I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
Charles
9/19/2007 8:59:16 PM

I tried:

Dim row As GridViewRow
row = CType(sender, GridViewRow)
myCommand = New SqlCommand("Update Tickets Set Closed='Yes',ClosedDate='" & DateTime.Now & "' WHERE TicketID='" & GridView1.DataKeys(row.RowIndex).Values("TicketID") & "' ", conStr1)

but I'm getting this error:

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.Button' to type 'System.Web.UI.WebControls.GridViewRow'.

I have to go as well. Thanks again for your help,
Mark
 


Embrace the chaos, only with chaos will we ever see change.
0
Silverblade1486
9/19/2007 9:12:43 PM

You have to get to the row to do the cast, and the button is contained in the row.  I'm rusty in VB, but let's try:

row = CType(sender.parent, GridViewRow)

or however parent/child relationships are managed in VB.  Maybe it's .container.  I'm a C# guy. 

 


I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
Charles
9/20/2007 12:24:52 PM

I tried to figure it out this way, but unfortunately I couldn't get it to work.  I did some more research and I was able to find these two articles in C# : http://www.eggheadcafe.com/articles/20011210.asp and http://forums.asp.net/t/1036001.aspx.  (the first article is the most informative.)  

Using these articles I was able to convert my button to use CommandEventArgs instead of System.EventArgs in the Event Handler of the button's click event.  The most important step was to set the correct options of the button

ex: <asp:button id="button1" CommandArgument='<# Eval("ID_Field_Name")%>' CommandName="" OnCommand="Name_of_Event_Handler" runat="server />)

Once that was done I could access e.CommandArgument and retrieve the value of the ID field for use in my SQL Statement.

Thanks again for your help!  Hopefully this will help someone else with the same objective,
Mark
 


 


Embrace the chaos, only with chaos will we ever see change.
0
Silverblade1486
9/21/2007 8:11:59 PM
Reply:

Similar Artilces:

How to retrieve data row and hiddenField values in <TemplateField> GridView and show it in a TextBox by clicked on each row not Select Command button
asp:GridView ID="GridviewHelpdesk" DataSourceID="srcTransfers" DataKeyNames="IDHelpdesk"    AutoGenerateColumns="false" GridLines="Horizontal" runat="server" AllowPaging="true"    BorderWidth="0px" BackColor="White" CellPadding="2" CellSpacing="0" BorderStyle="None"    BorderColor="#CCCCCC" Font-Names="Arial" PagerSettings-Position="Bottom" PagerSettings-Mode="Numeric"    Pag...

How to delete controls in GridView when the delete button in a row is clicked
Hi,   I am having issues with my gridview.....i added 2 dropdown and 2 compare validators....whenever i delete a row though......the dropdown and compare validators are becoming null........thus when i click a button, it is still validating.............anyway to delete this when i click the delete button or even handle?   Please help.  ...

retrieving from row # to row #.
I have over 750 000 rows to retrieve from a table using a datawindow, but my system can only handle approx 30 000 rows and I would like to start from the end of the table. Is it possible to set the row numbers to retrieve? For example, start the retrieve from row 750 000 and stop at row 720 000. There must be a way. thanks, Vern what backend are you using? <Vern> wrote in message news:6BA241541AAD7F2F0063357385256C40.0063358685256C40@webforums... > I have over 750 000 rows to retrieve from a table using a datawindow, but > my system can only handle approx 30 ...

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 ...

Iwant to select a row and column in gridview with select radiobutton. but No checked change event.below put a button .if click that button to seleced row values will select
I want to select a row and column in gridview using radiobutton in gridview . if which radio button is select that row will select and i want that row column values in outside individual textboxes of next page.  but in that only single radiobutton will select and no post back="true" bcz iam not using checked change property. i inserted button below gridview. if i click the that selected row and columns values are stored into textboxes of next page im using this code .but im getting one column in that row. but i want all columns in that selected row so plz repla...

how to compare rows in the datatable and remove the duplicate rows (before removal of duplicate row i need to append those values to original rows)
Hii.             I have a datatable in that i have some rows.. i need to compare those rows one among the other based on first column only. If its duplicate row i need to append those col values to original row. For example here is the data in the table.: Total - 13 columns Name:     Jan:   Feb:   March:...............................Dec  Phani      2        4          ...

Referencing BoundField Datafield values of Datagrid row when button on same row is selected????
Given the Gridview below: When I select the button "Rate" and fall into this code: How can I reference "carriercode" and other . Apparently selecting the button does not select the row. I've tried find control, and everything returns that I must reference and instance of the object.  CommandArgument is being sent corrently. If the button were a buttonfield I would have no problem getting the row index, but Im having problems because the button is an asp.net runat server button. snip...  Protected Sub PendingGridView_RowCommand(ByVal sender As Object, By...

adding / deleting table rows, and accessing controls within added rows
Hi everyone,I would like to know what is a good and simple way to achieve this using asp.net.  Basically i would like the ability to add and delete rows, preferably table rows.  Against each row is its delete button, hitting it will delete the corresponding row.  There is only 1 Add button to add a new row.  In each row, there are say 2 textboxes.  When i hit, say a calculate button, i wish to be able to access all the available textboxes in all the available rows in the event handler, and say just output a sum.If GridView is suggested, could you please explain why i...

Delete Control Button in Gridview Row at RowDataBound
I'd like to Delete a Control Button in a Gridview Row at RowDataBound, based on certain criteria.  I can locate the control during the event routine, but:Set = nothing gives "read only"Dispose =  has no effect Any suggestions on how I might be able to delete this button in this situation would be appreciated.Thanks!(PS:  one alt is to ADD the button in row created under the opposite criteria...I was hoping the get the above approach to work first, since it allows vanilla generation of the button.)  got it...in RowDatabound....If e.Row.RowType = D...

How to make template control invisible based on another col value (row by row)
In a gridview, I have a template like the following: <EditItemTemplate> <asp:DropDownList ID="ddl1" selectedValue='<%# Bind("id_hill_confidence") %>' ...> <asp:TextBox Runat="server" Text='<%# Bind("crit_variance") %>' ID="TextBox1" </EditItemTemplate> I want to check another value in the row (crit_show) and if it is 1 or true, I want tl make TextBox1.visible=true, otherwise I want to make it false (invisible). How can I do this on a row by row basis. I know how ...

Trying to delete a row, I get "Row changed between retrieve and update."
Hi Trying to delete a row I get the following error message and can't figure out why. Please see error below and any suggestion will be appreciated. Thanks Error message and part of the script: Row changed between retrieve and update. No changes made to database. DELETE FROM q_code_cause WHERE code = 1 AND ... Ok I found the Problem! Thanks anyway "Wasap" <edgadon@medicalcardsystem.com> wrote in message news:3f96a7a5@forums-2-dub... > Hi > > Trying to delete a row I get the following error message and can't figure > out why. Ple...

PB5: retrieving additional rows results in moving rows from deleted to primary buffer?
Hi! I have a datawindow where I do an initial retrieve and then have to add or remove some sets of rows from the database. I attempted to achieve adding row sets by doing additional (parameterized) retrieves while keeping the existing rows (by setting a return value of 2 in the retrievestart event). I remove sets by using deleterow() on the individual rows (moving rows to the deleted buffer). This works well until I have removed sets of rows and then add another set. It seems that rows that have previously been in the deleted buffer show up again in the primary buffer after issuing a...

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=&...

How concate n rows value into single row value
Daer Sir, I have list(5 rows) of name in a datawindow I want to concate all rows into sinle row regards Indus ---== Posted via the PFCGuide Web Newsreader ==--- http://www.pfcguide.com/_newsgroups/group_list.asp Are you trying to display it in one row in the same DW which retrieves the five separate rows ? Do you need those five rows for any processing other than concatenating them ? What functionality are you trying to provide ? Understanding that may help us provide other options. There are several approaches you could take, primarily revolving around reading each va...

Web resources about - Retrieve row value for row with delete button? - asp.net.presentation-controls

Facebook Developers Can Retrieve Users’ Profile Pictures In Different Sizes
Facebook introduced a way for developers to retrieve users’ profile pictures for use within their applications in different sizes, rather than ...

Winston retrieves the news - Flickr - Photo Sharing!
... food and losing weight. Three months ago, we were told he had lymphosarcoma of the GI tract. On March 10, 2008, Winston was called to go retrieve ...

Dolphin retrieves phone for a lady after it fell in the ocean - YouTube
Dolphin retrieves phone for a lady after it fell in the ocean

Man killed by train after jumping on tracks to retrieve something
A man has been killed by a train after jumping onto the tracks to retrieve something at Wentworthville Station.

People Are Willing To Go To Extreme Lengths To Retrieve Their Stolen Smartphones
People are willing to pay a ton of money and potentially put themselves in danger to retrieve their stolen smartphones, a new survey has found. ...

NSA surveillance program can retrieve, replay phone calls
The NSA has built a voice interception program capable of recording 100 per cent of a foreign country's calls and replaying voices from calls ...

Divers retrieve body from NSW floodwaters
A woman's body has been retrieved from a submerged car in a creek in Maitland.

Tourist plunges to death from Potts Point rooftop park trying to retrieve football: police
A French tourist who fell to his death from a rooftop park in Potts Point in inner Sydney was attempting to retrieve a football that had gone ...

Rescuers retrieve bodies after Brazilian tour bus crash kills 54
At least 54 people have been killed after a tour bus plunged hundreds of metres into a densely wooded ravine in southern Brazil, authorities ...

Investigators retrieve more human remains at MH17 crash site in eastern Ukraine but wreckage cannot yet ...
Dutch forensic experts recover further human remains at the crash site of downed flight MH17.

Resources last updated: 12/13/2015 5:18:43 PM