Showing posts with label cell. Show all posts
Showing posts with label cell. Show all posts

Saturday, March 31, 2012

Set asp:tablecell text from javascript

on my form i got a table with cell like this:
<asp:TableCell ID="tdNavigation_Sub" Runat="server"></asp:TableCell>
To set the text that goes in here from the code behind is easy... just:
protected TableCell tdNavigation_Sub; and tdNavigation_Sub.Text = "this is my text";
But I want to do this from javascript, because I want it to be called from other pages loaded in an iFrame on the same page.
On this kids, I will just call "parent.myscript("blah blah");"...easy

but i canot get the javascript on the main form right...so pls help?
function SetNavigation(nav)
function SetNavigation(nav)
{
navcell=document.getElementById("tdNavigation_Sub");
navcell.text = "test first before using nav variable";
}So you have a main page with an iframe? The iframe contains the tablecells right?
Are you getting a javascript error?
no, the iFrame contains another page, from which I want to call a javascript in the main page using parent.myscript("...
I created a test and got it to work. Let me know if this is what you are looking for...

1-Create a separate .js file...

function changecell()
{
var mycell;
mycell=parent.document.getElementById("tablecell_changeMe");
mycell.innerHTML='this is madness';
}


2-Create a file that will be your iframe...

<%@. Page Language="vb" AutoEventWireup="false" Codebehind="iframe1.aspx.vb" Inherits="TableCellExample.iframe1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>iframe1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" src="http://pics.10026.com/?src=JScript1.js"></script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 103; LEFT: 32px; WIDTH: 208px; POSITION: absolute; TOP: 40px; HEIGHT: 24px"
onclick="changecell()" type="button" value="Button Test from Iframe">
</form>
</body>
</HTML>

3-Create the main page and add the iframe tag...

<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" src="http://pics.10026.com/?src=JScript1.js">
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Table id="Table1" style="Z-INDEX: 100; LEFT: 32px; POSITION: absolute; TOP: 32px" runat="server"
Width="208px" Height="120px">
<asp:TableRow></asp:TableRow>
<asp:TableRow></asp:TableRow>
<asp:TableRow>
<asp:TableCell ID="tablecell_changeMe">test cell 1</asp:TableCell>
<asp:TableCell>test cell 2</asp:TableCell>
<asp:TableCell>test cell 3</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br>
<br>
<!-- Okay here is our iframe -->
<iframe id="myiframe" src="http://pics.10026.com/?src=iframe1.aspx" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 392px; POSITION: absolute; TOP: 184px; HEIGHT: 176px">
</iframe><INPUT style="Z-INDEX: 103; LEFT: 32px; WIDTH: 72px; POSITION: absolute; TOP: 400px; HEIGHT: 24px"
type="button" value="Button" onclick="changecell()">
</form>
</body>
</HTML>

Let me know if you have problems with the test above.
Maybe all you needed changed was...

navcell=parent.document.getElementById("tdNavigation_Sub");
Thanks!

Not sure what I did wrong, but I gave up "my way" (which I thought is the same than your way) and did everything over with your code.
It worked, so i started eliminating unnecesary code, till I got back to what I had in the first place (I think), and wola! .. it worked still.

Thanks again mate!
no problem, glad it worked. :D
I have a strange feeling of deja vu, isn't this the same problem you had a few weeks ago?
Yeah..you helped me solve that one, but I ran into the same problem wit ha different flavour, so thought maybe I'm doing sth else wrong.

Just been using JScript a lot lately...I should get a book and work through it, but TIME man!!!

Thursday, March 29, 2012

set cell color while rendered in a datagrid

I use the code: <asp:BoundColumn DataField="EFF_END_DT"
SortExpression="EFF_END_DT" HeaderText="Effective End"
DataFormatString="{0:d}">
<ItemStyle ForeColor= '<% # MyColor(
DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
</asp:BoundColumn>
to have red date is it is over and blue if not!
But I get an error:
Compiler Error Message: BC30676: 'DataBinding' is not an event of
'System.Web.UI.WebControls.TableItemStyle'.
how can I resolve this?i think your trying to user the OnItemDataBound method
In this method you can access each row of your datagrid, and from there
determine if the date should be read or not.
in the .aspx page
<asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" ....
then in the .cs page
public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
{
//From here you can access your bound column and set the colors
}
"Ofer" <Ofer@.discussions.microsoft.com> wrote in message
news:574957A7-2D07-44A7-95BD-69B36E77C458@.microsoft.com...
>I use the code: <asp:BoundColumn DataField="EFF_END_DT"
> SortExpression="EFF_END_DT" HeaderText="Effective End"
> DataFormatString="{0:d}">
> <ItemStyle ForeColor= '<% # MyColor(
> DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
> </asp:BoundColumn>
> to have red date is it is over and blue if not!
> But I get an error:
> Compiler Error Message: BC30676: 'DataBinding' is not an event of
> 'System.Web.UI.WebControls.TableItemStyle'.
> how can I resolve this?
>
Thanks! that was helpful.
Would you know why if the results is 2 rows the event fires 4 times
2 times with the value I axpect an 2 with " "
my vb is:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Debug.WriteLine(e.Item.Cells(6).GetType.ToString) 'always
System.Web.UI.WebControls.TableCell
Debug.WriteLine(e.Item.Cells(6).Text)
End Sub
End Class
"Grant Merwitz" wrote:

> i think your trying to user the OnItemDataBound method
> In this method you can access each row of your datagrid, and from there
> determine if the date should be read or not.
> in the .aspx page
> <asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" ....
> then in the .cs page
> public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
> {
> //From here you can access your bound column and set the colors
> }
>
> "Ofer" <Ofer@.discussions.microsoft.com> wrote in message
> news:574957A7-2D07-44A7-95BD-69B36E77C458@.microsoft.com...
>
>
You can use
If e.Item.ItemType = ListItemType.Item OrElse
e.Item.ItemType = ListItemType.AlternatingItem Then
' Your code here
End If
HTH
Elton Wang
elton_wang@.hotmail.com

>--Original Message--
>Thanks! that was helpful.
>Would you know why if the results is 2 rows the event
fires 4 times
>2 times with the value I axpect an 2 with " "
>my vb is:
> Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
>System.Web.UI.WebControls.DataGridItemEventArgs) Handles
>DataGrid1.ItemDataBound
> Debug.WriteLine(e.Item.Cells
(6).GetType.ToString) 'always
>System.Web.UI.WebControls.TableCell
> Debug.WriteLine(e.Item.Cells(6).Text)
> End Sub
>End Class
>"Grant Merwitz" wrote:
>
datagrid, and from there
OnItemDataBound="MyGrid_OnItemDataBound" ....
DataGridItemEventArgs e)
set the colors
message
69B36E77C458@.microsoft.com...
>'></ItemStyle>
an event of
>.
>

set cell color while rendered in a datagrid

I use the code:<asp:BoundColumn DataField="EFF_END_DT"
SortExpression="EFF_END_DT" HeaderText="Effective End"
DataFormatString="{0:d}">
<ItemStyle ForeColor= '<% # MyColor(
DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
</asp:BoundColumn>
to have red date is it is over and blue if not!
But I get an error:
Compiler Error Message: BC30676: 'DataBinding' is not an event of
'System.Web.UI.WebControls.TableItemStyle'.

how can I resolve this?i think your trying to user the OnItemDataBound method

In this method you can access each row of your datagrid, and from there
determine if the date should be read or not.

in the .aspx page
<asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" ....

then in the .cs page

public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
{
//From here you can access your bound column and set the colors
}

"Ofer" <Ofer@.discussions.microsoft.com> wrote in message
news:574957A7-2D07-44A7-95BD-69B36E77C458@.microsoft.com...
>I use the code: <asp:BoundColumn DataField="EFF_END_DT"
> SortExpression="EFF_END_DT" HeaderText="Effective End"
> DataFormatString="{0:d}">
> <ItemStyle ForeColor= '<% # MyColor(
> DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
> </asp:BoundColumn>
> to have red date is it is over and blue if not!
> But I get an error:
> Compiler Error Message: BC30676: 'DataBinding' is not an event of
> 'System.Web.UI.WebControls.TableItemStyle'.
> how can I resolve this?
Thanks! that was helpful.
Would you know why if the results is 2 rows the event fires 4 times
2 times with the value I axpect an 2 with " "

my vb is:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Debug.WriteLine(e.Item.Cells(6).GetType.ToString) 'always
System.Web.UI.WebControls.TableCell
Debug.WriteLine(e.Item.Cells(6).Text)
End Sub
End Class

"Grant Merwitz" wrote:

> i think your trying to user the OnItemDataBound method
> In this method you can access each row of your datagrid, and from there
> determine if the date should be read or not.
> in the .aspx page
> <asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" ....
> then in the .cs page
> public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
> {
> //From here you can access your bound column and set the colors
> }
>
> "Ofer" <Ofer@.discussions.microsoft.com> wrote in message
> news:574957A7-2D07-44A7-95BD-69B36E77C458@.microsoft.com...
> >I use the code: <asp:BoundColumn DataField="EFF_END_DT"
> > SortExpression="EFF_END_DT" HeaderText="Effective End"
> > DataFormatString="{0:d}">
> > <ItemStyle ForeColor= '<% # MyColor(
> > DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
> > </asp:BoundColumn>
> > to have red date is it is over and blue if not!
> > But I get an error:
> > Compiler Error Message: BC30676: 'DataBinding' is not an event of
> > 'System.Web.UI.WebControls.TableItemStyle'.
> > how can I resolve this?
>
You can use

If e.Item.ItemType = ListItemType.Item OrElse
e.Item.ItemType = ListItemType.AlternatingItem Then
' Your code here
End If

HTH

Elton Wang
elton_wang@.hotmail.com

>--Original Message--
>Thanks! that was helpful.
>Would you know why if the results is 2 rows the event
fires 4 times
>2 times with the value I axpect an 2 with " "
>my vb is:
> Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
>System.Web.UI.WebControls.DataGridItemEventArgs) Handles
>DataGrid1.ItemDataBound
> Debug.WriteLine(e.Item.Cells
(6).GetType.ToString) 'always
>System.Web.UI.WebControls.TableCell
> Debug.WriteLine(e.Item.Cells(6).Text)
> End Sub
>End Class
>"Grant Merwitz" wrote:
>> i think your trying to user the OnItemDataBound method
>>
>> In this method you can access each row of your
datagrid, and from there
>> determine if the date should be read or not.
>>
>> in the .aspx page
>> <asp:DataGrid id="MyGrid"
OnItemDataBound="MyGrid_OnItemDataBound" ....
>>
>> then in the .cs page
>>
>> public void MyGrid_OnItemDataBound(object Sender,
DataGridItemEventArgs e)
>> {
>> //From here you can access your bound column and
set the colors
>> }
>>
>>
>> "Ofer" <Ofer@.discussions.microsoft.com> wrote in
message
>> news:574957A7-2D07-44A7-95BD-
69B36E77C458@.microsoft.com...
>> >I use the code: <asp:BoundColumn DataField="EFF_END_DT"
>> > SortExpression="EFF_END_DT" HeaderText="Effective End"
>> > DataFormatString="{0:d}">
>> > <ItemStyle ForeColor= '<% # MyColor(
>> > DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%
>'></ItemStyle>
>> > </asp:BoundColumn>
>> > to have red date is it is over and blue if not!
>> > But I get an error:
>> > Compiler Error Message: BC30676: 'DataBinding' is not
an event of
>> > 'System.Web.UI.WebControls.TableItemStyle'.
>>> > how can I resolve this?
>>>>
>>
>>
>.

Set datagrid cell enabled to false

When a user hits the edit button, I want to either make a certain cell not enabled, or not visible. I don't care which. I can't seem to get either to work.

Here is my code that I tried:Dim cn As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;" _
& "Persist Security Info=False;" _
& "Initial Catalog=fuel info;" _
& "UID=;PWD=;" _
& "Data Source=Server7")
cn.Open()

Dim datAdapt As New OleDb.OleDbDataAdapter("Select Vendor_No as [Vendor No], " & _
"Vendor_Name as [Vendor Name], Vendor_Terminal as [Vendor Terminal], " & _
"Vendor_Trmnl_No As [Terminal No], Vendor_City As [City], Vendor_State As " & _
"[State], ID From Other_Vendors Order By Vendor_Name", cn)

Dim datSet As New Data.DataSet

datAdapt.Fill(datSet, "Other_Vendors")

DataGrid1.DataSource = datSet
DataGrid1.DataKeyField = "ID"
DataGrid1.EditItemIndex = e.Item.ItemIndex
e.Item.Cells(3).Enabled = False
DataGrid1.DataBind()
cn.Close()
cn.Dispose()
datAdapt.Dispose()
datSet.Dispose()
As you can see, the line that is not working is "e.item.cells(3).enabled = false"

Also, if anyone knows how to set the width of the cell on the fly as well, I would appreciate that as well.

ThanksTry looking into the ItemDataBound sub and adding

e.Item.Cells(3).Enabled = False

in there. You cant disable the cells before the data is in them. RIght now you are trying to disable that cell before the data has been bound to the grid.

Jerel
Phelnglai, that did the trick. One more quick question. Could you set the cell width from the same place? If so, do you know the syntax? Thanks.

What about the cell header? What would the syntax be for that?

Thanks again!
Nevermind, I see that if you just increase the width of the actual datagrid, the fields will increase and adjust on their own at run time.
Glad you got it. Sorry I never answered your second question. I was in a car wreck and am just now getting back to work and doing thinks.

If you have any other questions, feel free to ask.

Jerel

Saturday, March 24, 2012

Set focus to DAtagrid Cell

I hae a WEB application that uses a datagrid. My first 2 rows are Template
columns with Dropdown lists. My Third column as databound cell. When I go
to edit a particular row I want the focus to change to the third row. I am
using Visual Studio VB.Net with WEB Forms. Any Help would be great.It is not clear what exactly you want. Anyway, setting focus is a
client-side task. You have to produce some javascript which will operate on
the client DHTML presentation of the grid.

Eliyahu

"rroca" <oeb@.homexperts.net> wrote in message
news:C3CD2487-6FD7-4830-A20D-E14E18CA56F1@.microsoft.com...
> I hae a WEB application that uses a datagrid. My first 2 rows are
Template
> columns with Dropdown lists. My Third column as databound cell. When I
go
> to edit a particular row I want the focus to change to the third row. I
am
> using Visual Studio VB.Net with WEB Forms. Any Help would be great.

Set focus to DAtagrid Cell

I hae a WEB application that uses a datagrid. My first 2 rows are Template
columns with Dropdown lists. My Third column as databound cell. When I go
to edit a particular row I want the focus to change to the third row. I am
using Visual Studio VB.Net with WEB Forms. Any Help would be great.It is not clear what exactly you want. Anyway, setting focus is a
client-side task. You have to produce some javascript which will operate on
the client DHTML presentation of the grid.
Eliyahu
"rroca" <oeb@.homexperts.net> wrote in message
news:C3CD2487-6FD7-4830-A20D-E14E18CA56F1@.microsoft.com...
> I hae a WEB application that uses a datagrid. My first 2 rows are
Template
> columns with Dropdown lists. My Third column as databound cell. When I
go
> to edit a particular row I want the focus to change to the third row. I
am
> using Visual Studio VB.Net with WEB Forms. Any Help would be great.