Datagrid binding

T

thomson

Hi all,
Iam binding a datatable with the data grid, In the data table
there is a column as Posted_flag char(1), which can have value either N
or Y .
My issue is that in my grid there is a an
item template with a checkbox control, depending upon the value, Y or N
it should show checked or unchecked.
What should i do for this ?

Thanks in Advance

Thomson
 
K

Ken Cox [Microsoft MVP]

Hi Thomson,

You can use an IIF() function to test the incoming value of Posted_flag and
then let it check or uncheck the box. Here's some code:

<asp:templatecolumn HeaderText="Y/N">
<itemtemplate>
<asp:checkbox id="Checkbox2" runat="server" Checked='<%#
IIF(Container.DataItem("Posted_flag")="Y","true","false") %>' >
</asp:checkbox>
</itemtemplate>
</asp:templatecolumn>

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
 
T

thomson

Hi KEn

Line 136: <HEADERSTYLE VerticalAlign="Top"
HorizontalAlign="Center" Wrap="False"></HEADERSTYLE>
Line 137: <ITEMTEMPLATE>
Line 138: <asp:CheckBox ID="chkPosted" Runat="server"
checked='<%# IIF(Container.DataItem("Posted_Flag")=="Y","true","false")
%>' ></asp:CheckBox>
Line 139: </ITEMTEMPLATE>
Line 140: <EDITITEMTEMPLATE>


Source File: c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx
Line: 138



Show Detailed Compiler Output:


CMicrosoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx(138,52):
error CS0118: 'System.Web.UI.WebControls.DataGridItem.DataItem' denotes
a 'property' where a 'method' was expected
c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx(138,38):
error CS0103: The name 'IIF' does not exist in the class or namespace
'ASP.TransactionPosting_aspx'

What might be the problem?
Regards

thomson
Hi Thomson,

You can use an IIF() function to test the incoming value of Posted_flag and
then let it check or uncheck the box. Here's some code:

<asp:templatecolumn HeaderText="Y/N">
<itemtemplate>
<asp:checkbox id="Checkbox2" runat="server" Checked='<%#
IIF(Container.DataItem("Posted_flag")="Y","true","false") %>' >
</asp:checkbox>
</itemtemplate>
</asp:templatecolumn>

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


thomson said:
Hi all,
Iam binding a datatable with the data grid, In the data table
there is a column as Posted_flag char(1), which can have value either N
or Y .
My issue is that in my grid there is a an
item template with a checkbox control, depending upon the value, Y or N
it should show checked or unchecked.
What should i do for this ?

Thanks in Advance

Thomson
 
T

thomson

Hi ken
i got something like this

Line 1922: #line 138
"c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx"
Line 1923: target.Checked =
((bool)(DataBinder.Eval(Container,"DataItem.Posted_Flag")=="Y" ? True :
False));
Line 1924:
Line 1925: #line default
Line 1926: #line hidden
Line 1927: }
in the complete compilation source

and it says

CS0103: The name 'True' does not exist in the class or namespace
'ASP.TransactionPosting_aspx'
Help me out

Regards

thomson
Hi KEn

Line 136: <HEADERSTYLE VerticalAlign="Top"
HorizontalAlign="Center" Wrap="False"></HEADERSTYLE>
Line 137: <ITEMTEMPLATE>
Line 138: <asp:CheckBox ID="chkPosted" Runat="server"
checked='<%# IIF(Container.DataItem("Posted_Flag")=="Y","true","false")
%>' ></asp:CheckBox>
Line 139: </ITEMTEMPLATE>
Line 140: <EDITITEMTEMPLATE>


Source File: c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx
Line: 138



Show Detailed Compiler Output:


CMicrosoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx(138,52):
error CS0118: 'System.Web.UI.WebControls.DataGridItem.DataItem' denotes
a 'property' where a 'method' was expected
c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx(138,38):
error CS0103: The name 'IIF' does not exist in the class or namespace
'ASP.TransactionPosting_aspx'

What might be the problem?
Regards

thomson
Hi Thomson,

You can use an IIF() function to test the incoming value of Posted_flag and
then let it check or uncheck the box. Here's some code:

<asp:templatecolumn HeaderText="Y/N">
<itemtemplate>
<asp:checkbox id="Checkbox2" runat="server" Checked='<%#
IIF(Container.DataItem("Posted_flag")="Y","true","false") %>' >
</asp:checkbox>
</itemtemplate>
</asp:templatecolumn>

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


thomson said:
Hi all,
Iam binding a datatable with the data grid, In the data table
there is a column as Posted_flag char(1), which can have value either N
or Y .
My issue is that in my grid there is a an
item template with a checkbox control, depending upon the value,
Y
or N
 
K

Ken Cox [Microsoft MVP]

Oh. You didn't say you were using C#. IIF is a VB thing. Need to find the
comparable C# syntax.

thomson said:
Hi KEn

Line 136: <HEADERSTYLE VerticalAlign="Top"
HorizontalAlign="Center" Wrap="False"></HEADERSTYLE>
Line 137: <ITEMTEMPLATE>
Line 138: <asp:CheckBox ID="chkPosted" Runat="server"
checked='<%# IIF(Container.DataItem("Posted_Flag")=="Y","true","false")
%>' ></asp:CheckBox>
Line 139: </ITEMTEMPLATE>
Line 140: <EDITITEMTEMPLATE>


Source File: c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx
Line: 138



Show Detailed Compiler Output:


CMicrosoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx(138,52):
error CS0118: 'System.Web.UI.WebControls.DataGridItem.DataItem' denotes
a 'property' where a 'method' was expected
c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx(138,38):
error CS0103: The name 'IIF' does not exist in the class or namespace
'ASP.TransactionPosting_aspx'

What might be the problem?
Regards

thomson
Hi Thomson,

You can use an IIF() function to test the incoming value of Posted_flag and
then let it check or uncheck the box. Here's some code:

<asp:templatecolumn HeaderText="Y/N">
<itemtemplate>
<asp:checkbox id="Checkbox2" runat="server" Checked='<%#
IIF(Container.DataItem("Posted_flag")="Y","true","false") %>' >
</asp:checkbox>
</itemtemplate>
</asp:templatecolumn>

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


thomson said:
Hi all,
Iam binding a datatable with the data grid, In the data table
there is a column as Posted_flag char(1), which can have value either N
or Y .
My issue is that in my grid there is a an
item template with a checkbox control, depending upon the value, Y or N
it should show checked or unchecked.
What should i do for this ?

Thanks in Advance

Thomson
 
J

Juan T. Llibre

You can use the conditional operator
or conditional ternary operator:

bool booleanStatement = true;
string resultValue = booleanStatement ? "The true part" : "The false part;

// set to "The true part"



Juan T. Llibre
ASP.NET MVP
===========
Ken Cox said:
Oh. You didn't say you were using C#. IIF is a VB thing. Need to find the
comparable C# syntax.

thomson said:
Hi KEn

Line 136: <HEADERSTYLE VerticalAlign="Top"
HorizontalAlign="Center" Wrap="False"></HEADERSTYLE>
Line 137: <ITEMTEMPLATE>
Line 138: <asp:CheckBox ID="chkPosted" Runat="server"
checked='<%# IIF(Container.DataItem("Posted_Flag")=="Y","true","false")
%>' ></asp:CheckBox>
Line 139: </ITEMTEMPLATE>
Line 140: <EDITITEMTEMPLATE>


Source File: c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx
Line: 138



Show Detailed Compiler Output:


CMicrosoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx(138,52):
error CS0118: 'System.Web.UI.WebControls.DataGridItem.DataItem' denotes
a 'property' where a 'method' was expected
c:\inetpub\wwwroot\finance\FINANCE\TransactionPosting.aspx(138,38):
error CS0103: The name 'IIF' does not exist in the class or namespace
'ASP.TransactionPosting_aspx'

What might be the problem?
Regards

thomson
Hi Thomson,

You can use an IIF() function to test the incoming value of Posted_flag and
then let it check or uncheck the box. Here's some code:

<asp:templatecolumn HeaderText="Y/N">
<itemtemplate>
<asp:checkbox id="Checkbox2" runat="server" Checked='<%#
IIF(Container.DataItem("Posted_flag")="Y","true","false") %>' >
</asp:checkbox>
</itemtemplate>
</asp:templatecolumn>

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


Hi all,
Iam binding a datatable with the data grid, In the data table
there is a column as Posted_flag char(1), which can have value either N
or Y .
My issue is that in my grid there is a an
item template with a checkbox control, depending upon the value, Y or N
it should show checked or unchecked.
What should i do for this ?

Thanks in Advance

Thomson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top