Xaphas
Xaphas

Reputation: 519

ASP.NET: Get rid of " " in Gridview

So I am currently getting a format-error (and rightfully so), because of this value. I think it is some sort of unicode space-alternative or something.

This is how I call the value:

int updatecount = Convert.ToInt32(row.Cells[2].Text);

This is the value while debugging: enter image description here

I need the value to be numeric OR null. Did anyone have similar problems?

UPDATE: This is how I assigned the value:

CODE BEFORE enter image description here

<asp:BoundField ReadOnly="true" DataField="BASKET_ID" DataFormatString="" />
<asp:TemplateField HeaderText="Vertrags-Beginn">
    <ItemTemplate>
        <asp:TextBox runat="server" ID="STARTINGDATE"  Text='<%# ((DateTime)(Eval("CONTRACT_POS_START"))).ToShortDateString() %>'>
        </asp:TextBox><ajaxToolkit:CalendarExtender runat="server" Format="dd.MM.yyyy" ID="startingdatecalendar" TargetControlID="STARTINGDATE" />
    </ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Anzahl Tage" DataField="DAYCOUNT"  />

CODE BEHIND

Basket_Grid.DataSource = cdbe.VwBaskets.ToList();
Basket_Grid.DataBind();

Upvotes: 0

Views: 3495

Answers (2)

fnostro
fnostro

Reputation: 4591

try something like this

int updatecount = ( IsNumeric(String.row.Cells[2].Text) ? Convert.ToInt32(String.row.Cells[2].Text) : 0 );

Upvotes: 1

Saurin Vala
Saurin Vala

Reputation: 1928

try HtmlDecode

It will convert string that has been HTML-encoded for html transmission into decoded string.

int updatecount = Convert.ToInt32(Server.HtmlDecode(row.Cells[2].Text));

Or

 int updatecount = Convert.ToInt32(row.Cells[2].Replace("&nbsp;", ""));

Upvotes: 3

Related Questions