Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Edit String Before Gridview Display

Edit String Before Gridview Display

Scheduled Pinned Locked Moved ASP.NET
databasecsharpwpfwcfsysadmin
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VengefulSakhmet
    wrote on last edited by
    #1

    I am just starting to use ASP and am very green to its data structures, so I'm probably going about this completely wrong. On the C# side I have connected to the database and taken the info I need, but I need to strip the string of the extension before it's displayed on the asp side. Without the whole table and databinding, I would feel confident doing this, but with these two factors I'm not sure how to go about this. Is there any easy way to make my query into a table and then edit that table's entries, and set that to the datasource for binding, or am I looking at this the wrong way?

        SqlConnection conn = new SqlConnection(ConnectionPath);
        conn.Open();
        string queryClasses = "SELECT WSS\_Content.dbo.AllDocs.LeafName FROM 
    

    WSS_Content.dbo.AllDocs LEFT OUTER JOIN WSS_Content.dbo.RecycleBin ON WSS_Content.dbo.AllDocs.Id =
    WSS_Content.dbo.RecycleBin.DocId WHERE (WSS_Content.dbo.RecycleBin.DocId IS NULL) AND (WSS_Content.dbo.AllDocs.Extension = 'zip')";
    SqlCommand availableClasses = new SqlCommand(queryClasses, conn);
    SqlDataReader reader = availableClasses.ExecuteReader();
    SQLQueryClassListings.DataSource = reader;
    SQLQueryClassListings.DataBind();
    reader.Close();

    <asp:GridView ID="SQLQueryClassListings" AutoGenerateColumns="false" runat="server" 
    

    BorderWidth="1px" BackColor="White" CellPadding="5" BorderColor="DodgerBlue" HeaderStyle-
    BackColor="#0147FA" HeaderStyle-ForeColor="White">
    <Columns>
    <asp:BoundField HeaderText="Class Titles" DataField="LeafName" />
    <asp:ButtonField ButtonType="Button" HeaderText="Register" Text="Register"/>
    </Columns>
    </asp:GridView>

    C A 2 Replies Last reply
    0
    • V VengefulSakhmet

      I am just starting to use ASP and am very green to its data structures, so I'm probably going about this completely wrong. On the C# side I have connected to the database and taken the info I need, but I need to strip the string of the extension before it's displayed on the asp side. Without the whole table and databinding, I would feel confident doing this, but with these two factors I'm not sure how to go about this. Is there any easy way to make my query into a table and then edit that table's entries, and set that to the datasource for binding, or am I looking at this the wrong way?

          SqlConnection conn = new SqlConnection(ConnectionPath);
          conn.Open();
          string queryClasses = "SELECT WSS\_Content.dbo.AllDocs.LeafName FROM 
      

      WSS_Content.dbo.AllDocs LEFT OUTER JOIN WSS_Content.dbo.RecycleBin ON WSS_Content.dbo.AllDocs.Id =
      WSS_Content.dbo.RecycleBin.DocId WHERE (WSS_Content.dbo.RecycleBin.DocId IS NULL) AND (WSS_Content.dbo.AllDocs.Extension = 'zip')";
      SqlCommand availableClasses = new SqlCommand(queryClasses, conn);
      SqlDataReader reader = availableClasses.ExecuteReader();
      SQLQueryClassListings.DataSource = reader;
      SQLQueryClassListings.DataBind();
      reader.Close();

      <asp:GridView ID="SQLQueryClassListings" AutoGenerateColumns="false" runat="server" 
      

      BorderWidth="1px" BackColor="White" CellPadding="5" BorderColor="DodgerBlue" HeaderStyle-
      BackColor="#0147FA" HeaderStyle-ForeColor="White">
      <Columns>
      <asp:BoundField HeaderText="Class Titles" DataField="LeafName" />
      <asp:ButtonField ButtonType="Button" HeaderText="Register" Text="Register"/>
      </Columns>
      </asp:GridView>

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Ideally you would edit your data source before binding, by doing substrings inside your SQL. You can also iterate over the data source before binding. You can also write your column definition so that it calls a method and passes in the data source, so you can return whatever string you like based on the data.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      V 1 Reply Last reply
      0
      • C Christian Graus

        Ideally you would edit your data source before binding, by doing substrings inside your SQL. You can also iterate over the data source before binding. You can also write your column definition so that it calls a method and passes in the data source, so you can return whatever string you like based on the data.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        V Offline
        V Offline
        VengefulSakhmet
        wrote on last edited by
        #3

        I don't think substring will work for me because the column I am selecting has differing string lengths and from what I googled, it appears I need to know the length of the string I wish to keep. Perhaps there is a sql command I missed. I was trying to do a while loop "while(reader.Read())", but I wasn't sure exactly how to handle the reader contents. I had assumed that since it is a reader that I cannot write to its contents. Am I wrong in this assumption? I had tried to assign each iteration of reader to a string array, but that does not appear to be the path I wish to go down. My main issue is understanding what data type is coming out of reader and what format its data must be to be accepted during databinding. So, am I right about the reader and is the table idea bad? Thanks!

        C 1 Reply Last reply
        0
        • V VengefulSakhmet

          I don't think substring will work for me because the column I am selecting has differing string lengths and from what I googled, it appears I need to know the length of the string I wish to keep. Perhaps there is a sql command I missed. I was trying to do a while loop "while(reader.Read())", but I wasn't sure exactly how to handle the reader contents. I had assumed that since it is a reader that I cannot write to its contents. Am I wrong in this assumption? I had tried to assign each iteration of reader to a string array, but that does not appear to be the path I wish to go down. My main issue is understanding what data type is coming out of reader and what format its data must be to be accepted during databinding. So, am I right about the reader and is the table idea bad? Thanks!

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          OK, it looked to me like you wanted to drop the extension, so, the last four characters.

          VengefulSakhmet wrote:

          I was trying to do a while loop "while(reader.Read())"

          I would fill a dataset and iterate over that.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          1 Reply Last reply
          0
          • V VengefulSakhmet

            I am just starting to use ASP and am very green to its data structures, so I'm probably going about this completely wrong. On the C# side I have connected to the database and taken the info I need, but I need to strip the string of the extension before it's displayed on the asp side. Without the whole table and databinding, I would feel confident doing this, but with these two factors I'm not sure how to go about this. Is there any easy way to make my query into a table and then edit that table's entries, and set that to the datasource for binding, or am I looking at this the wrong way?

                SqlConnection conn = new SqlConnection(ConnectionPath);
                conn.Open();
                string queryClasses = "SELECT WSS\_Content.dbo.AllDocs.LeafName FROM 
            

            WSS_Content.dbo.AllDocs LEFT OUTER JOIN WSS_Content.dbo.RecycleBin ON WSS_Content.dbo.AllDocs.Id =
            WSS_Content.dbo.RecycleBin.DocId WHERE (WSS_Content.dbo.RecycleBin.DocId IS NULL) AND (WSS_Content.dbo.AllDocs.Extension = 'zip')";
            SqlCommand availableClasses = new SqlCommand(queryClasses, conn);
            SqlDataReader reader = availableClasses.ExecuteReader();
            SQLQueryClassListings.DataSource = reader;
            SQLQueryClassListings.DataBind();
            reader.Close();

            <asp:GridView ID="SQLQueryClassListings" AutoGenerateColumns="false" runat="server" 
            

            BorderWidth="1px" BackColor="White" CellPadding="5" BorderColor="DodgerBlue" HeaderStyle-
            BackColor="#0147FA" HeaderStyle-ForeColor="White">
            <Columns>
            <asp:BoundField HeaderText="Class Titles" DataField="LeafName" />
            <asp:ButtonField ButtonType="Button" HeaderText="Register" Text="Register"/>
            </Columns>
            </asp:GridView>

            A Offline
            A Offline
            Anurag Gandhi
            wrote on last edited by
            #5

            You can try something like:

            string queryClasses = "select left(WSS_Content.dbo.AllDocs.LeafName, charindex('.', WSS_Content.dbo.AllDocs.LeafName, 0) - 1) from ...

            Instead of charindex you might want lastIndexOf kind of thing. Please check this link: http://www.sqlservercentral.com/scripts/T-SQL+Aids/31116/[^] Hope this will help.

            Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups