Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Probs in: Data grid calculated column Itemtemplate

Reply
Thread Tools

Probs in: Data grid calculated column Itemtemplate

 
 
Raghu Raman
Guest
Posts: n/a
 
      05-12-2005
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,"postalc ode"))%>
</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 ***
 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      05-14-2005
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



<aspataGrid 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.DataIte m,"postalcode")))%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>


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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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,"postalc ode"))%>
> </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 ***



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview control and sorting a calculated templatefield column ? markm75c@msn.com ASP .Net 2 06-14-2006 01:49 AM
urg-how to sort datagrid having calculated column samir ASP .Net 0 12-21-2005 02:41 AM
Help Pls.Data grid itemtemplate Raghu Raman ASP .Net Datagrid Control 2 05-12-2005 12:01 PM
calculated column in datagrid question =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= ASP .Net 3 03-23-2005 06:55 PM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM



Advertisments