Change 2 text fields: another way of doing it??

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
I have a datagrid, have 5 text fields displayed on it.

If I'm in ModeA, i want the first Col to have , for example, "Company".

If I'm in ModeB, I want the first Col to have, for example, "Contact"...

so depending on the mode, I want to change one or 2 text fields ...

I can have a panel and just display the right panel for the right mode..but was wondering if there's another way of changing the textfield without using panels...
 
This is what I want:

Mode1:

Company
Address
...

Mode2:
Contact
Address
....

So, display a totally different header in Mode2, update a different field ...Dont want to put this in a panel just because only 2 fields are different from Mode1 and Mode2..


This is what I have:
Code:
[b]<ItemTemplate>[/b]
<table border="0">
	<tr>
		<td align="left"><b>[b]Company:[/b]</b></td>
		<td>
		 <%# Container.DataItem("cmp_name1") %>
		 </td>
	</tr>
	<tr>
		<td align="left"><b>[b]Address:[/b]</b></td>
		<td>
		 <%# Container.DataItem("cmp_account") %>
	 </td>
</tr>
</table>
[b]</itemtemplate>[/b]
[b]<EditItemTemplate>[/b]
<table border="0">
	<tr>
	 <td align="left"><b>[b]Company:[/b]</b></td>
	 <td>
		 <%# Container.DataItem("cmm_name1") %>
	 </td>
	 </tr>
<tr>
	 <td align="left"><b>[b]Address:[/b]</b></td>
	 <td>
		 <%# Container.DataItem("addr") %>
	 </td>
</tr>
....
[edit]Removed tabs:Robby[/edit]
 
Last edited by a moderator:
Yes, something in the DB. When the user logs in, the choose either Mode1 or Mode2...

The "Mode" that I keep in a session variable decides what to display...

But not sure how to do it in a datagrid..as I've shown below...

Any help to get me going would be great..thanks..
 
In the Front:
Switch to something like inside the Template:
<td align="left"><b><asp:literal id="txtLabel" runat="server"/></b></td>

Also add a not-visible BoundColumnwith whatever is the witch
<asp:BoundColumn visible="false" DataField="SwitchValue"/>

In Code:
Use the "OnItemDataBound" event... and you can change the text of the Literal Control based on the value of the BoundColumn
 
Hmm, couldnt find good examples of what u described..I tried this site:

http://aspnet.4guysfromrolla.com/articles/020503-1.aspx

I'm using a template.., I think i need to break that template and add a "boundcolumn" ...but then wasnt sure how to do the databinding to the database...

so I did this I've seen it in an ASP page...wonder if it's ok to do this in ASP.Net..it does display the info correctly...

Code:
<tr>[b] <% if session("Mode") = "22" then %>[/b]
    <td align="left"><b>Company:</b></td>
    <td>
	<%# Container.DataItem("cmp") %>
    </td>
	[b]<%else%>[/b]
    <td align="left"><b>Contact:</b></td>
    <td>
	<%# Container.DataItem("contact") %>
    </td>
	[/b]<%end if %>[/b]
	
</tr>
 
Back
Top