Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   Probs in: Data grid calculated column Itemtemplate (http://www.velocityreviews.com/forums/t761976-probs-in-data-grid-calculated-column-itemtemplate.html)

Raghu Raman 05-12-2005 07:30 PM

Probs in: Data grid calculated column Itemtemplate
 
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 ***

Ken Cox [Microsoft MVP] 05-14-2005 02:22 AM

Re: Probs in: Data grid calculated column Itemtemplate
 
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.DataIte m,"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" <raghuraman_ace@rediffmail.com> wrote in message
news:OtuKDkyVFHA.3620@TK2MSFTNGP09.phx.gbl...
> 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 ***





All times are GMT. The time now is 09:12 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.