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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Datgrid formatting

Datgrid formatting

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
4 Posts 2 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.
  • A Offline
    A Offline
    alwinSCH
    wrote on last edited by
    #1

    Hey, on m first webproject, I would like to fill a datagrid at runtime and one column that is filled there has to be a function on that value so the filling of the datagrid works fine Dim voorw As String voorw = "select date,name,codefrom T_leven_ToDo where Sessie = '" & CStr(Session.SessionID) & "'" Dim daresult As New SqlDataAdapter(voorw, objconnection) Dim ds As New DataSet daresult.Fill(ds, "T_leven_ToDo") DataGrid1.DataSource = ds DataGrid1.DataMember = "T_leven_ToDo" DataGrid1.DataBind() But now i want to let a function work on the value of column0 and show this result in column0! This I don't know how to do, please can anybody help me?

    M 1 Reply Last reply
    0
    • A alwinSCH

      Hey, on m first webproject, I would like to fill a datagrid at runtime and one column that is filled there has to be a function on that value so the filling of the datagrid works fine Dim voorw As String voorw = "select date,name,codefrom T_leven_ToDo where Sessie = '" & CStr(Session.SessionID) & "'" Dim daresult As New SqlDataAdapter(voorw, objconnection) Dim ds As New DataSet daresult.Fill(ds, "T_leven_ToDo") DataGrid1.DataSource = ds DataGrid1.DataMember = "T_leven_ToDo" DataGrid1.DataBind() But now i want to let a function work on the value of column0 and show this result in column0! This I don't know how to do, please can anybody help me?

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, What you might need to do is to create a TemplateColumn for the column 0, then you can add a call to a function in the data binding expression. The result of the function is bound to the column. You can take a look at the document for more information: Data-Binding Expressions for Web Forms Pages[^]

      A 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, What you might need to do is to create a TemplateColumn for the column 0, then you can add a call to a function in the data binding expression. The result of the function is bound to the column. You can take a look at the document for more information: Data-Binding Expressions for Web Forms Pages[^]

        A Offline
        A Offline
        alwinSCH
        wrote on last edited by
        #3

        Ok Thnx it has put me in the good direction, But a little more help would be welcome. Now I have created a template column didn't assign a templateitem to it, what i wanna do for the moment is to get the first column out my dataset("table") formatted with a function who is defined in a class 'datumclass.vb' and assign the output of this function to the template column but i do not know how to start or what to do! Please has anybody an example of this!

        M 1 Reply Last reply
        0
        • A alwinSCH

          Ok Thnx it has put me in the good direction, But a little more help would be welcome. Now I have created a template column didn't assign a templateitem to it, what i wanna do for the moment is to get the first column out my dataset("table") formatted with a function who is defined in a class 'datumclass.vb' and assign the output of this function to the template column but i do not know how to start or what to do! Please has anybody an example of this!

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          You don't need to get through all the columns of the table, and select the first column and bind it to the template column of the datagrid. What you need to do is to specify the column name in the data binding expression, then the control automatically pulls data out of the column. For example, the first column name is DOB:

          <asp:TemplateColumn HeaderText="DOB">
          <ItemTemplate>
          <asp:Label id="Label1" runat="server">
          <%# MyCustomFunction((DateTime)DataBinder.Eval(Container,"DataItem.DOB"))%>
          </asp:Label>
          </ItemTemplate>
          </asp:TemplateColumn>

          In the server side code, you have a method named with MyCustomFunction:

          protected string MyCustomFunction(DateTime dob)
          {
          //Now you can pass the value of the dob parameter to a custom function defined elsewhere, then returns the result as normal.
          ...
          }

          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