Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid, manual row add

Status
Not open for further replies.

HomerJS

Programmer
Jun 25, 2001
86
US

I'm using the following select statement to populate a datagrid on a .net web page.

select ITEM_CODE_KEY, CHARGE_AMT, FS_CHARGE_AMT, HAULERS_AMT, FS_HAULERS_AMT
from ITEM_CHARGE_DETL
where ORDER_NO = 12345 and OWNER_NO = 98765


My problem is I want to use one field if it's not zero (or null), otherwise use another field to populate the column.

When I use the following HTML it returns an error of 'Expression expected.' What am I doing wrong, or is there a better way of doing this?

<asp:TemplateColumn>
<ItemTemplate>
<asp:Label>
<%# if databinder.eval(container.dataitem, &quot;FS_CHARGE_AMT&quot;) <> 0 then
databinder.eval(container.dataitem, &quot;FS_CHARGE_AMT&quot;)
else
databinder.eval(container.dataitem, &quot;CHARGE_AMT&quot;)
endif %>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
 
Check the Item Created Event That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Oh ya sorry. Was really busy this morning.

I haven't tried this but it should work. Make the column in question to be a template column. Name the label in the item bit to something such as lblCharge.

Create an event handler for the item Created Event.
Within, it check to see if the value is blank if it is put in the other value.

Like I said this is entirely theoritical, I haven't tried it but it should work.

To the others reading this if I am wrong feel free to correct me. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Below is part of what I have in the HTML and related code behind page. I'm trying to put the values in an ordinary label to check that I have everything correct before I put it in the grid. No data shows up in the label. Am I way off in what I'm doing or what do I need to change? The third cell of the datagrid does have a value in it.

HTML page ===================
<asp:datagrid id=&quot;ItmChrgGrid&quot; style=&quot;Z-INDEX: 142; LEFT: 24px; POSITION: absolute; TOP: 168px&quot; runat=&quot;server&quot; OnItemCreated=&quot;Item_Created&quot; Width=&quot;712px&quot; AutoGenerateColumns=&quot;False&quot;>
<AlternatingItemStyle BackColor=&quot;WhiteSmoke&quot;></AlternatingItemStyle>
<HeaderStyle HorizontalAlign=&quot;Center&quot;></HeaderStyle>
<Columns>
<asp:BoundColumn DataField=&quot;ITEM_CODE_KEY&quot; HeaderText=&quot;Item Code&quot;>
<HeaderStyle Width=&quot;100px&quot;></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label ID=&quot;lblChgAmt&quot;>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>


Code behind page =================

Sub Item_Created(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Label1.Visible = True
If e.Item.ItemIndex >= 0 Then Label1.Text = e.Item.ItemIndex & &quot; - &quot; & e.Item.Cells(2).Text & &quot; * &quot;
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top