Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

web app datagrid - adding/using edit button to grid items

Posted on 2004-11-01
7
Medium Priority
?
168 Views
Last Modified: 2010-04-23
Hi,

     I have a datagrid that's bound to a table.  I've inserted a new column in VB.NET and put an Edit button in it.  So what I see is my grid with an "Edit" button next to each item.  How do I now use code to:

1) determine when edit has been clicked
2) determine which index was chosen

Thanks!

JP
0
Comment
Question by:gleznov
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 

Author Comment

by:gleznov
ID: 12466785
For clarity, I right-clicked the datagrid, chose edit template, dragged a button into a new column, called it cmdEdit, and now I want to know how I code for the event of someone pressing an edit button next to whatever record?

JP
0
 
LVL 4

Accepted Solution

by:
vinhthuy_nguyen earned 2000 total points
ID: 12470539
Hi,
Datagrid was made to do a lot of works for you, You just declare the property, and it will do.
This is from my application and it works great.
In declare a datagrid, you use something like this :

OnDeleteCommand="delete_grid"
OnUpdateCommand="update_grid"
OnCancelCommand="cancel_edit"
OnEditCommand="edit_grid"

and in the column
+use this for the delete column
<asp:ButtonColumn ItemStyle-Width="20" CommandName="delete" Text="<img border=0
src=Images/delete.gif>"></asp:ButtonColumn>

+this is for the column you want to be edited :

<ItemTemplate>
<asp:HyperLink Runat=server ID="Hyperlink2"><%#Bind you data here%>
</asp:HyperLink>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edit_cat_name" Runat=server Text='<%#DataBinder.Eval(Container.DataItem,"cat_name")%>' >
</asp:TextBox>
</EditItemTemplate>

+this for the edit/cancel/update

<asp:EditCommandColumn ItemStyle-Width="120" EditText="<img border=0 alt=Edit src=Images/edit.gif>" CancelText=" Cancel" UpdateText="Update |" ItemStyle-Font-Name="Tahoma" ItemStyle-Font-Bold="True" ItemStyle-Font-Size="8"></asp:EditCommandColumn>

And now, in the codebehind,

Sub edit_grid(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles news_in_cat.EditCommand
        news_in_cat.EditItemIndex = e.Item.ItemIndex
        BindGrid()
    End Sub
Sub cancel_edit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
        news_in_cat.EditItemIndex = -1
        BindGrid()
End Sub
Sub delete_grid(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
        'Pls delete this (CType(news_in_cat.DataKeys(e.Item.ItemIndex), Integer))

        status.Text = i.ToString + "row(s) affetted "
        news_in_cat.EditItemIndex = -1
    BindGrid()
   
   
    End Sub
    Public Sub update_grid(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles news_in_cat.UpdateCommand

        Dim update_value as String
        update_value = CType(e.Item.Cells(your column number).FindControl("your column name"), TextBox).Text
Update this CType(news_in_cat.DataKeys(e.Item.ItemIndex), Integer)
        news_in_cat.EditItemIndex = -1

        BindGrid()

    End Sub

Pls suit it in your application, hope this helps
0
 

Author Comment

by:gleznov
ID: 12472128
I didn't code the datagrid, I just dragged, dropped, and then edited template.  I'll see if I can apply the above, I still get confused when altering the HTML with ASP code.  

JP
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:gleznov
ID: 12472142
Is there a way just to make the button indicate the index?  I don't really want to do the editing w/in the grid, but using controls above the grid.  So when they click that "edit" button, I want it to tell my program to fill the control boxes with the information found at that index in the dataset, then after the change I'll update the database, dataset, and rebind the datagrid.

JP
0
 

Author Comment

by:gleznov
ID: 12485657
OK this isn't working for me.  Could someone please lead me on a step by step way of:

1) making a new column at the front of the grid
2) sticking a button with text "Edit" in that column so that it appears by each row
3) accessing an edit-button-clicked event in code?

I have 1 and 2 working right (I think) but in case I did something wrong, please be thorough.

JP
0
 
LVL 4

Expert Comment

by:vinhthuy_nguyen
ID: 12505833
Hi buddy, sorry for a late answer
Acctually I'm kind of stuck in my company works. Sorry, and pls check these links , may be that helps.
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q689q
http://www.dotnet247.com/247reference/msgs/7/35621.aspx

Regards.
0
 

Author Comment

by:gleznov
ID: 12522955
Got it!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question