473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Editing GridView in DetailsView

I have gridview with a detailsview below. When I click on 'New' in brings up the DetailsView for inserting. When I click on 'Edit' in does not brink up the DetailsView. What am I doing wrong? I totally at a loss, please help. I don't know if I need to something to grdUserProfile_RowEditing. Thank you! This is some of my code behind:
Expand|Select|Wrap|Line Numbers
  1. protected void grdUserProfile_RowEditing(object sender, GridViewEditEventArgs e)
  2.  {
  3. }
  4.  
  5. protected void grdUserProfile_RowCommand(object sender, GridViewCommandEventArgs e)
  6.         {
  7.             if (e.CommandName == "Insert")
  8.             {
  9.                 grdUserProfile.DataSourceID = "";
  10.                 grdUserProfile.DataBind();
  11.                 DetailsView dv = this.grdUserProfile.Controls[0].Controls[0].FindControl("dvUserProfile") as DetailsView;
  12.                 dv.ChangeMode(DetailsViewMode.Insert);
  13.             }
  14.             else
  15.                 if (e.CommandName == "Edit")
  16.                 {
  17.                     grdUserProfile.DataSourceID = "";
  18.                     grdUserProfile.DataBind();
  19.                     DetailsView dv = this.grdUserProfile.Controls[0].Controls[0].FindControl("dvUserProfile") as DetailsView;
  20.                     dv.ChangeMode(DetailsViewMode.Edit);
  21.                 }
  22.         }
  23.  
  24. <asp:GridView ID="grdUserProfile" runat="server" AllowPaging="True"
  25.         CellPadding="4" Font-Names="Arial" Font-Size="Small" ForeColor="#333333" Width="100%" 
  26.         OnRowDataBound="grdUserProfile_OnRowDataBound" AutoGenerateColumns="False"
  27.         OnRowCancelingEdit="grdUserProfile_RowCancelingEdit"
  28.         OnRowCommand="grdUserProfile_RowCommand" OnPageIndexChanging="grdUserProfile_PageIndexChanging"
  29.         OnRowUpdating="grdUserProfile_RowUpdating"
  30.         OnRowDeleting="grdUserProfile_RowDeleting"
  31.         OnRowEditing="grdUserProfile_RowEditing"
  32.         >
  33.         <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  34.     <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  35.             <EmptyDataTemplate>
  36.                 <asp:DetailsView ID="dvUserProfile" runat="server" AutoGenerateRows="False" CellPadding="4"
  37.                     DataKeyNames="ssn" ForeColor="#333333" GridLines="None"
  38.                     Height="25px" OnItemInserting="dvUserProfile_ItemInserting"
  39.                     OnModeChanging="dvUserProfile_ModeChanging" 
  40.                     Width="421px">
  41.                     <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  42.                     <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
  43.                     <EditRowStyle BackColor="#999999" />
  44.                     <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  45.                     <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  46.                     <Fields>
  47. <asp:TemplateField HeaderText="SSN" SortExpression="id">
  48.                             <ItemTemplate>
  49.                                 <%#Eval ("ssn") %>
  50.                             </ItemTemplate>
  51.                             <InsertItemTemplate>
  52.                                 <asp:TextBox ID="txtSSN" runat="server" 
  53.                                 Text='<%# Bind("ssn") %>' MaxLength="<%# 11 %>"></asp:TextBox>
  54.                             </InsertItemTemplate>
  55.                             <EditItemTemplate>
  56.                                 <asp:TextBox OnDataBinding="DetailsViewtxtSSN_DataBinding" ID="txtSSN" runat="server" 
  57.                                 Text='<%# Bind("ssn") %>' MaxLength="<%# 11 %>"></asp:TextBox>
  58.                             </EditItemTemplate>
  59.                         </asp:TemplateField>
  60. <asp:TemplateField HeaderText="Rank" SortExpression="id">
  61.                             <ItemTemplate>
  62.                                 <%#Eval ("rank") %>
  63.                             </ItemTemplate>
  64.                             <InsertItemTemplate>
  65.                                 <asp:DropDownList OnDataBinding="DetailsViewddlRank_DataBinding" ID="ddlRank" runat="server" AutoPostBack="false" DataTextField="rank"
  66.                                 DataValueField="rank" SelectedValue='<%# Bind("rank") %>' >
  67.                                 </asp:DropDownList>
  68.                             </InsertItemTemplate>
  69.                             <EditItemTemplate>
  70.                                 <asp:DropDownList OnDataBinding="DetailsViewddlRank_DataBinding" ID="ddlRank" runat="server" AutoPostBack="false" DataTextField="rank"
  71.                                 DataValueField="rank" SelectedValue='<%# Bind("rank") %>' >
  72.                                 </asp:DropDownList>
  73.                             </EditItemTemplate>
  74.                         </asp:TemplateField>
  75. <asp:CommandField ShowEditButton="True" />
  76.                         <asp:CommandField ShowInsertButton="True" />
  77.                     </Fields>
  78. <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" Width="100px" />
  79.                     <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  80.                     <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  81.                 </asp:DetailsView>
  82.             </EmptyDataTemplate>
  83.             <EditRowStyle BackColor="#999999" />
  84.             <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
  85.             <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  86.             <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  87.             <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  88.         <Columns>
  89. <asp:BoundField DataField="ssn" HeaderText="SSN" Visible="False" ReadOnly="True" />
  90.             <asp:BoundField DataField="rank" HeaderText="Rank" Visible="False"/>
  91.             <asp:ButtonField CommandName="Insert" Text="New" />
  92.             <asp:ButtonField CommandName="Edit" Text="Edit" />
  93.             <asp:TemplateField>
  94.         <ItemTemplate>
  95.             <asp:LinkButton ID="LinkButton1" 
  96.                 CommandArgument='<%# Eval("ssn") %>' 
  97.                 CommandName="Delete" runat="server">
  98.                 Delete</asp:LinkButton>
  99.         </ItemTemplate>
  100.    </asp:TemplateField>
  101.         </Columns>
  102.     </asp:GridView>
Thank you!
Jul 17 '07 #1
1 4983
Please check http://bytes.com/topic/asp-net/answe...ew-detailsview. You may find the solution.
Sep 29 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Giorgio | last post by:
Hi, I have a dropdown menu with categories and when a category is selected the Gridview is binded with sub-categories. Then when a sub-category is selected a detailsview is displayed...
1
by: Jim McGivney | last post by:
In VS-05 on an aspx page I have a GridView with a select item column. When the select button is pressed a DetailsView control opens with the selected record displayed. The user can now edit the...
1
by: K B | last post by:
I just installed VS 2005...both GridView and DetailsView, I'm using a SQLdataSource and both controls do NOT have a checkbox for Enable Editing. Help please!!! Thanks, Kit
2
by: nolan | last post by:
I have an asp.net 2.0 page with a gridview and detailsview on the same page set up in a master-details scenario. The gridview and detailsview have separate SQL data sources. The user enters...
1
by: needin4mation | last post by:
Not sure what I'm doing wrong here. I have a gridview and a detailsview. The detailsview is set to insert by default. When I insert data the detailsview it works. The data goes in the database....
0
by: luvdairish | last post by:
Controls (in order on page) 1.)GridView - each row is a work order w/ a link for details in the last column 2.)DetailsView - when user clicks on link from above GridView, the details are shown...
0
by: luvdairish | last post by:
Controls (in order on page) 1.)GridView - each row is a work order w/ a link for details in the last column 2.)DetailsView - when user clicks on link from above GridView, the details are shown...
2
by: mike | last post by:
I have a page with a LoginView which contains a Gridview and a DetailsView, each in its own UpdatePanel The problem that I am experiencing is that when I select a record in the Gridview (using a...
1
by: vineetbindal | last post by:
Hi all, I have a datagrid and detailsview. when a user selects a row in datagrid onSelectedIndexchanged is fired and Detailsview comes into picture. I want to display the data of the selected row...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.