By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

Editing GridView in DetailsView

P: 1
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
Share this Question
Share on Google+
1 Reply


P: 4
Please check http://bytes.com/topic/asp-net/answe...ew-detailsview. You may find the solution.
Sep 29 '11 #2

Post your reply

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