Edit Mode in DetailsView

Last post 09-21-2009 1:05 PM by zoocar. 25 replies.

Sort Posts:

  • Re: Edit Mode in DetailsView

    04-24-2008, 3:07 PM
    Answer
    • All-Star
      60,104 point All-Star
    • anas
    • Member since 09-21-2006, 8:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,788
    • Moderator

    Yes , sorry , you need to use the Decoded version of The Apostrophe , for more info see this thread : http://forums.asp.net/t/1237088.aspx

     

    so you need this :

     

    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
       OnClientClick='<%# Eval("EmailAddress","return confirm(&#039;Do you wish to delete <{0}> ?&#039;);" ) %>'
       Text="Delete">
    </asp:LinkButton>
     
    Regards,

    Anas Ghanem | Blog

  • Re: Edit Mode in DetailsView

    04-24-2008, 3:27 PM
    • Member
      19 point Member
    • jbchen
    • Member since 03-04-2008, 2:08 PM
    • Posts 59

    wow... I never thought of that.  Thank you!

    anas:

    Yes , sorry , you need to use the Decoded version of The Apostrophe , for more info see this thread : http://forums.asp.net/t/1237088.aspx

     

    so you need this :

    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
       OnClientClick='<%# Eval("EmailAddress","return confirm(&#039;Do you wish to delete <{0}> ?&#039;);" ) %>'
       Text="Delete">
    </asp:LinkButton>
     
  • Re: Edit Mode in DetailsView

    04-24-2008, 3:33 PM
    • All-Star
      60,104 point All-Star
    • anas
    • Member since 09-21-2006, 8:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,788
    • Moderator

    I'm happy because it helped you  ...

     

    Regards,

    Regards,

    Anas Ghanem | Blog

  • Re: Edit Mode in DetailsView

    04-24-2008, 3:55 PM
    • Member
      19 point Member
    • jbchen
    • Member since 03-04-2008, 2:08 PM
    • Posts 59

    One question, I'm not sure if that's simple to do,  now  I added a bcc column in GridView.   This column gets extremely long without any spaces

    firstuser@email.com;seconduser@email.com;thirduser@email.com;......

    I try to set the width to fixed-length and wrap to true, it still didn't wrap around to the next line.  gridview is now very large because of this bcc column.   

     

    <asp:TemplateField HeaderText="bcc" SortExpression="bcc" ItemStyle-Width="20" ItemStyle-Wrap="true">

    <EditItemTemplate>

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("bcc") %>'></asp:TextBox>

    </EditItemTemplate>

    <ItemTemplate>

    <asp:Label ID="Label1" runat="server" Text='<%# Bind("bcc") %>'></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    Thanks
  • Re: Edit Mode in DetailsView

    04-24-2008, 4:41 PM
    Answer
    • All-Star
      60,104 point All-Star
    • anas
    • Member since 09-21-2006, 8:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,788
    • Moderator

    Hi....

    Yes , if there is no spaces in the text , it will not wrap ... i believe there is a simple solution for that ..

    you can put the label inside a Div , and use the horizaonatal scrolling for that ( you need to adjust the width instead of 50px )

     

                        <asp:TemplateField HeaderText="bcc" SortExpression="bcc" ItemStyle-Width="50">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("bcc") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <div style="width: 50px; overflow: scroll;">
                                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("bcc") %>'></asp:Label>
                                </div>
                            </ItemTemplate>
                        </asp:TemplateField>
     

     

    Regards,

    Anas Ghanem | Blog

  • Re: Edit Mode in DetailsView

    04-24-2008, 5:06 PM
    • Member
      19 point Member
    • jbchen
    • Member since 03-04-2008, 2:08 PM
    • Posts 59

    hmm... that's clever,  It would be better look if I could display first 50 characters of bcc and put 3 dots (...)  after 50th characters.  and have a tooltip which show all characters when user highlight the bcc field on the page.  And most of the time, bcc field is empty,   I wrote If-then statement but it failed.

    Compiler Error Message: CS1525: Invalid expression term 'if'

     

         <asp:Label ID="Label1" runat="server" Text='<%# if Eval("bcc").Length>50 { Eval("bcc").Substring(0,50) } else {Eval("bcc")} %>'></asp:Label>


     

     

  • Re: Edit Mode in DetailsView

    04-25-2008, 10:18 AM
    Answer
    • All-Star
      60,104 point All-Star
    • anas
    • Member since 09-21-2006, 8:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,788
    • Moderator

    Yes, you need to do that in GridView RowDatabound:

     

    C#: 

      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // get a refernce to the label 
                Label lbl = e.Row.FindControl("Label1") as Label;
                if (lbl.Text.Length > 50)
                {
                    string tooltip = lbl.Text;
                    string lblText = lbl.Text.Substring(0, 50) + "...";
    
                    lbl.ToolTip = tooltip;
                    lbl.Text = lblText;
    
                }
                else
                {
                    lbl.ToolTip = lbl.Text;
                }
    
         }
      }

     

    VB:

     

     Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
         If e.Row.RowType = DataControlRowType.DataRow Then
             ' get a refernce to the label
             Dim lbl As Label = TryCast(e.Row.FindControl("Label1"), Label)
             If lbl.Text.Length > 50 Then
                 Dim tooltip As String = lbl.Text
                 Dim lblText As String = lbl.Text.Substring(0, 50) + "..."
                
                 lbl.ToolTip = tooltip
                    
                 lbl.Text = lblText
             Else
                 lbl.ToolTip = lbl.Text
                
             End If
         End If
     End Sub
     
     
    Regards,

    Anas Ghanem | Blog

  • Re: Edit Mode in DetailsView

    04-25-2008, 1:21 PM
    • Member
      19 point Member
    • jbchen
    • Member since 03-04-2008, 2:08 PM
    • Posts 59

    Thanks Anas, it works like a charm.  

    Question,  how do you filter data in gridview (without going back to sql server),  I'm assuming we hide the rows right?   So if I have an inputbox 'txtName', enter the data and submit, gridview should only display data which matches the Name of employee.

     

     

  • Re: Edit Mode in DetailsView

    04-25-2008, 2:41 PM
    Answer
    • Member
      19 point Member
    • jbchen
    • Member since 03-04-2008, 2:08 PM
    • Posts 59

    I think I figured it out myself.   Although it did go back to SQL server to get the data again when doing filter.   Not sure there is any way I can prevent that.  Thanks for all the teachings. 

     

    if (IsPostBack)

    {

    if (txtName.Text.Length > 0)

    SqlDataSource1.FilterExpression = "Name like '%" + txtName.Text + "%'";

    else

    SqlDataSource1.FilterExpression = "";

    GridView1.DataBind();

    }

  • Re: Edit Mode in DetailsView

    08-20-2009, 4:46 PM
    • Member
      6 point Member
    • zoocar
    • Member since 08-05-2009, 12:24 PM
    • Posts 5

    Anas,

    I've taken your code above and made some tweaks and have it working grand. But... how can I make this gridview column a hyperlink, more specifically , a NavigateURL with a replace script that I had working in my aspx page.

    NavigateUrl='<%# replace(container.dataitem("Link"),"Z:\","C:\") %>'

  • Re: Edit Mode in DetailsView

    09-21-2009, 1:05 PM
    • Member
      6 point Member
    • zoocar
    • Member since 08-05-2009, 12:24 PM
    • Posts 5

    A public function did the trick here:

    <asp:Label ID="Label1" Text='<%# CheckItem(Container.DataItem("fieldName")) %>' Runat="server" />

    In the code section, create the 'CheckItem' function:

    Public Function CheckItem(ByVal sItem as String) as String
    If sItem<>"" then
        Return sItem
    Else
        Return "n/a"
    End If

Page 2 of 2 (26 items) < Previous 1 2