tags:

views:

51

answers:

2

hi guys, I have a gridview in which when i click edit,update and cancel button comes.I have a variable named status.If status=false Then update should change to insert anf if status=true then update should be update itself.What code i hve to write in rowcammand for this?

<asp:TemplateField >
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit" Text="Edit">                      
                        </asp:LinkButton>
                     </ItemTemplate>
                     <EditItemTemplate>
                         <asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update" Text="Update">                      
                        </asp:LinkButton>
                         <asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel" Text="Cancel">                      
                        </asp:LinkButton>
                     </EditItemTemplate>
                </asp:TemplateField>
A: 

GridView is not designed for insert operations. You should use FormView or DetailView for the insert purpose.

Thought you can check if the record exists in GridView_RowCommand event, you need to filter the command of your interest using condiotnal match and write the code there.

for doing inserts with GridView this might help.

http://geekswithblogs.net/casualjim/articles/51360.aspx

this. __curious_geek
A: 

You could check for the id in the RowUpdating event and take it from there. You can also offload the decision to a stored proc in the database.

Steve