In a gridview, can I programatically control display of edit/delete buttons for selected row?

Hi there,

I'm sure this is something fairly straight forward but I'm only just getting used to working with gridviews so please help me,

I am displaying the select button on my gridview, and on the SelectedIndexChanged event I would like to add (or make visible) the edit and delete buttons just for the selected row - can I do this?

 All help appreciated,

JoH

0
JoH
5/25/2007 10:04:56 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
1642 Views

Similar Articles

[PageSpeed] 31
Get it on Google Play
Get it on Apple App Store

are you using template field with button / link button for

edit or delete button  ?


Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
5/25/2007 10:23:41 AM

 Hi,

 First thing if you are using asp:commandfield than my solution will not work, but my suggestion is that instead of commandfield use asp:TemplateField, and put link button inside that.

On the RowDataBound Event of gridview find that linkbutton and make visible = false like :

LinkButton temp = (LinkButton)e.Row.Cells[X].FindControl("linkbutton");

temp.visible = false.

 
and same case you reverse at the SelectedIndexChange event of GridView like this :

LinkButton temp = (LinkButton)GridView1.Row[GridView1.SelectedIndex].Cells[X].FindControl("linkbutton");

temp.visible =  true;

That's it.

Note: "linkbutton" is id of your link button inside gridview template field, and 'X' is cell no of your GridView. 

 
Hope this might solve your problem.

 
Happy Programming.

Regards,

Jay


 




Regards,
Jay Khanpara
0
Jay
5/25/2007 12:21:10 PM

Hi Jay,

Thanks for your help - I've got partial success with it!

I am using a template field, and I make the edit and delete linkButtons non-visible by default in the template definition.

Using your approach to make them visible in the SelectedIndexChanged event then works great using :

LinkButton editLinkButton = (LinkButton)GridView1.SelectedRow.FindControl("editLinkButton");

editLinkButton.Visible=true;

However, switching the edit and delete buttons off again is proving more problematic - your suggestion of doing it in the rowDataBound event gave me an error:

 Object reference not set to an instance of an object.

So I guess I need to find another suitable point to set visible=false - any suggestions?

Cheers,

Jo

0
JoH
5/30/2007 4:07:37 PM

Hi:

  Try this:

 protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
     
        foreach (GridViewRow r in this.GridView2.Rows) {
            if (r != this.GridView2.SelectedRow)
                r.FindControl("Button1").Visible = false;
            else r.FindControl("Button1").Visible = true;
        }
    }

             <asp:GridView AutoGenerateSelectButton="true" ID="GridView2" runat="server" DataSourceID="SqlDataSource1" OnRowDataBound="GridView2_RowDataBound" OnSelectedIndexChanged="GridView2_SelectedIndexChanged">
           <Columns>
           <asp:TemplateField><ItemTemplate>
               <asp:Button ID="Button1" runat="server" Text="Edit" CommandName="Edit" Visible="false" />
           </ItemTemplate>
           </asp:TemplateField>
           </Columns>
             </asp:GridView>

If it doesn't work, please inform us.

Regards


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
5/31/2007 7:48:33 AM

Worked a treat thank you.

0
JoH
6/4/2007 10:39:44 AM

Thanks for that code

But i want to Make Edit/Delete button with Gridview control programatically without using objectDatasource or SqlDataSourse

Help me

0
yasserzaid
1/11/2008 1:23:31 PM
Reply:

Similar Artilces:

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

How to display the more than one row with items and buttons in gridview control. when i select three items at same time from categories(Fruits, Apples, Gifts). The selected items are displayed in g
Hi,when i select three items at same time from categories(Fruits, Apples, Gifts). The selected items are displayed in gridview.Here i would like to change this way "when i click more than one category at same time. it should be display selected item and button."For example: if i have to select Fruits, Apples from categories.  it should be display like 1st "row have Fruits and In 2nd row have Apples and button" in gridview.the button have some event.How can i do it? Please can anyone answer me.With kind requestThanks your query is very raw..can u details it out...Pl...

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

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

Problem in Using DropDownList Control to select a selected row of SqlDataSource that is under GridView Control
Hi all,In my SQL Server Management Studio Express, I have a database "ChemDatabase" that has a table "LabData"  formatted in the following way: SampleID int PRIMARY KEY, SampleName nvarchar(25), ChemicalName, nvarchar(25), Concentration decimal(6.2) with 5 rows of records in this .dbo table. In my Visual Web Developer Express, I created a website "RPD-TCE" for extracting a row of record from the LabData table by using a DropDownList, a GridView and a SqlDataSource.  I want to click DropDownList to list one number of S...

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

GridView, Edit Row, user control button
I succesfully put a custom control inside a placeholder inside a cell when editing a row but when i click on a button or do anything which causes a postback the control disappears.protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e) { GridViewRow editrow = GridView1.Rows[GridView1.EditIndex]; PlaceHolder p1 = (PlaceHolder)editrow.FindControl("OptionsPlaceHolder"); DropDownList ddl1 = (DropDownList)sender; if (ddl1.SelectedItem.Text == "Combo") { Control uc1 = LoadControl("~/Us...

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 add the delete/edit buttons in GridView control ?
i have a GridView control that is bound dynamically to an AccessDataSource. the GridView control has the attribute 'AutoGenerateColumns' to be true. when i add a 'delete field' to the grid control (by code or by the edit columns feature), it gets added in the beginning of each row. however, i want it to be at the end of each row . how i can do it ? thanks  <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">                <Columns...

Select/Edit/Delete not working in Gridview control
I have a gridview control bound to a objectdatasource that's datasource is a tableadapter dataset.  However, with select, edit, and delete enabled the links are unclickable and do not work in the gridview control.  What am I doing wrong? Here is the source for the gridview control: <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding=&quo...

On Gridview
Hi guys, was hoping that someone may be able to help. When you click the select button, in a gridview's row, the select index is changed and the row is highlighted (within the css). But when i click the edit button on a gridview row the selectindex changed does not fire. Is there a simple way to fire the select index changed event, when clicking the edit button? I am using VS 2005, with VB. Any help is much appreciated ThanksPhil i think u hv used a AutoFormat option for ur GridView. So in that case the CSS get applied automatically for the Selected Row but not for EditingRow. ...

I can't get value of control in the selected row of a Gridview
I'm trying to perform an update using a sqldatasource from a gridview after a selection is made from a dropdown and a linkbutton "lbnUpdate" is clicked. I assigned  "select" as the command name of the linkbutton so I was assuming that I could then reference the gridviews selected row from the code behind but I guess I made a bad assumption. During debug there is "nothing" in the variable I use to capture the gridview selected row. I will post what I have. If I set AutoGenereateSelect button to true I can get the SelectedIndexChanged event...

How to check first and last row of a GridView so I can display different controls? thanks!
How to check first and last row of a GridView so I can display different controls? thanks! Do you want to display certain controls in the header and footer of the gridview control? HighOnCodingWanna get high! No, I want to display up and down arrow image on each row, but only down for first row and up for last row. IN the GridView ItemDataBound event you can check if the itemtype is item then you can make the images of up and down visible if its header or footer you can make up OR down images visible respectively. HighOnCodingWanna get high! I think the control has a count fu...

Help! Find row on which a button was pressed in the gridview control in .NET 2.0
How do you get the exact row (and column data from that row)  on which a button was pressed within a gridview. In .NET v1 using the datagrid control the followingconstruction was available:objArgs.Item.Cells(n).Textusing the datagrid DataGridCommandEventArgs parameter. choices in gridview are     Sub cmdBackTestSummary(ByVal objSender As Object, ByVal objArgs As GridViewCommandEventArgs) ' objArgs.commandname ' objargs.commandarguement ' objargs.commandsource     End Sub but no objArgs.Item.Cells(n) So how do you get the exact row (and c...

Web resources about - In a gridview, can I programatically control display of edit/delete buttons for selected row? - asp.net.presentation-controls

Programatically assigning a Customer Group in Magento
... or thousands. The Customer Group might change because you want the specific customer to be in a different group, or you might want to programatically ...

Authentication - LinkedIn Developer Network
Authentication Wed, 01/12/2011 - 12:12 — LIDeveloperAdmin LinkedIn Authorization When your application acts on behalf of our members, it's important ...

User plod - Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Stack Overflow Questions Tags Users Badges Unanswered Ask Question plod less info ...

Pipeline (Unix) - Wikipedia, the free encyclopedia
In Unix-like computer operating systems (and, to some extent, Microsoft Windows ), a pipeline is the original software pipeline : a set of processes ...

okTravel's Data Sources
Features information of where okTravel gets its data, and maybe even why certain data sources were chosen over others.

Text Readability Scores - Web Development in Brighton - Added Bytes
hi! neat script! the layout seems to be broken, though. I get loads of whitespace between the input box of the script and your last paragraph. ...

Startup News: Save Amit, and Hm, Not Too Many Launches Last Week
CONQUER THE WORLD. Startup Weekend just closed a partnership with the Kauffman Foundation ; now it’s announced a two-year agreement with Google ...

Blippy / The Blippy Blog
The Official Blippy.com Blog

On designing UIs for non-robots
In a typical, attentive human subject, the usual latency between a visual stimulus and a voluntary motor response is between 100 and 300 milliseconds. ...

DDS Hands On « Bulldozer00's Blog
Introduction In 2009, I downloaded RTI Inc.’s Data Distribution Service (DDS) communication middleware software developer kit along with a free ...

Resources last updated: 11/23/2015 8:10:02 PM