Probs in: Data grid calculated column Itemtemplate

Discussion in 'ASP .Net Datagrid Control' started by Raghu Raman, May 12, 2005.

  1. Raghu Raman

    Raghu Raman Guest

    Hi

    i just want to show 2 fields in the datagrid one is the customerid &
    other one is just the postal code field.I want to display the customer
    id as first column and the postalcode is to be multiplied(calculated
    column)by 2 as my second column while displaying.

    my datagrid settings are
    -------
    <Columns><asp:BoundColumn DataField="customerid"
    HeaderText="customerId"></asp:BoundColumn>
    <asp:BoundColumn DataField="postalcode"
    HeaderText="postalcode"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Values calculated">
    <ItemTemplate><%#
    Docals(DataBinder.Eval(Container.DataItem,"postalcode"))%>
    </ItemTemplate> </asp:TemplateColumn></Columns>
    -------
    my c#.net procedure (for Docals)
    -------------------------
    public string Docals(string postalcode)
    {return Convert.ToString(Convert.ToDouble(postalcode) * 2);
    }
    ----------------------Error--
    CS1502: The best overloaded method match for
    'Endavour.Hiddencols_.Docals(string)' has some invalid arguments
    *******Pls tell me where i went wrong.
    Regards & Thanks
    Raghu

    *** Sent via Developersdex http://www.developersdex.com ***
    Raghu Raman, May 12, 2005
    #1
    1. Advertising

  2. Raghu

    It looks like your helper function doesn't know that it is getting a string,
    so you have to force it to a string before you pass the value. See the code
    below. (Warning: I'm not strong in C#)

    Let us know if this helps?

    Ken
    Microsoft MVP [ASP.NET]
    Toronto



    <asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
    <Columns>
    <asp:BoundColumn DataField="customerid"
    HeaderText="customerId"></asp:BoundColumn>
    <asp:BoundColumn DataField="postalcode"
    HeaderText="postalcode"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Calculated">
    <ItemTemplate>
    <%# Docals(
    Convert.ToString(DataBinder.Eval(Container.DataItem,"postalcode")))%>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>


    private void Page_Load(object sender, System.EventArgs e)
    {
    DataGrid1.DataSource=CreateDataSource();
    DataGrid1.DataBind();
    }



    public string Docals(string postalcode)
    {
    return Convert.ToString(Convert.ToDouble(postalcode) * 2);
    }

    ICollection CreateDataSource()
    {

    // Create sample data for the DataGrid control.
    DataTable dt = new DataTable();
    DataRow dr;

    // Define the columns of the table.
    dt.Columns.Add(new DataColumn("postalcode", typeof(String)));
    dt.Columns.Add(new DataColumn("customerId", typeof(String)));
    dt.Columns.Add(new DataColumn("CurrencyValue", typeof(Double)));

    // Populate the table with sample values.
    for (int i=0; i<=10; i++)
    {
    dr = dt.NewRow();
    dr[0] = i;
    dr[1] = "Item " + i.ToString();
    dr[2] = 1.23 * (i + 1);
    dt.Rows.Add(dr);
    }

    DataView dv = new DataView(dt);
    return dv;

    }


    "Raghu Raman" <> wrote in message
    news:...
    > Hi
    >
    > i just want to show 2 fields in the datagrid one is the customerid &
    > other one is just the postal code field.I want to display the customer
    > id as first column and the postalcode is to be multiplied(calculated
    > column)by 2 as my second column while displaying.
    >
    > my datagrid settings are
    > -------
    > <Columns><asp:BoundColumn DataField="customerid"
    > HeaderText="customerId"></asp:BoundColumn>
    > <asp:BoundColumn DataField="postalcode"
    > HeaderText="postalcode"></asp:BoundColumn>
    > <asp:TemplateColumn HeaderText="Values calculated">
    > <ItemTemplate><%#
    > Docals(DataBinder.Eval(Container.DataItem,"postalcode"))%>
    > </ItemTemplate> </asp:TemplateColumn></Columns>
    > -------
    > my c#.net procedure (for Docals)
    > -------------------------
    > public string Docals(string postalcode)
    > {return Convert.ToString(Convert.ToDouble(postalcode) * 2);
    > }
    > ----------------------Error--
    > CS1502: The best overloaded method match for
    > 'Endavour.Hiddencols_.Docals(string)' has some invalid arguments
    > *******Pls tell me where i went wrong.
    > Regards & Thanks
    > Raghu
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    Ken Cox [Microsoft MVP], May 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bennett Haselton
    Replies:
    1
    Views:
    5,312
    Joe Fallon
    Sep 24, 2004
  2. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    calculated column in datagrid question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Mar 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    581
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Mar 23, 2005
  3. samir
    Replies:
    0
    Views:
    558
    samir
    Dec 21, 2005
  4. Replies:
    2
    Views:
    15,817
  5. Raghu Raman

    Help Pls.Data grid itemtemplate

    Raghu Raman, May 11, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    110
    Raghu Raman
    May 12, 2005
Loading...

Share This Page