I have a numeric Oracle field which stores -1 for true and 0 for
false. I am trying to populate a checkbox in a datagrid. In my SQL
statement, I used the Decode function so that when it populates the
dataset that I would store the string 'true' and 'false' rather than a
numeric value. I did this because I thought it would make it easier
to actually set the value in the checkbox. Anyway, I bind the dataset
to the datagrid. In my HTML code, the checkbox is contained in a
templatecolumn:
<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%#
(bool) DataBinder.Eval(Container.DataItem,
"strainer_on_fuel_line_bool") %>' Enabled="False"></asp:CheckBox
However, this will not work. It complains that "Specified cast is not
valid."
I have even tried it without the "(bool)" cast and it still didn't
work.
The data in my database has the value stored as either a -1 or 0. In
either case, I just want to set the check box to checked or unchecked.
I was even wondering if I needed to use one of the d atagrid's events
to do this.
Any ideas or help is appreciated.
Thanks,
MartySome suggestions
Try using a helper function to interpret your -1 or 0 instead of adjusting your recordset to return true or false
In your codebehind
protected bool GetCheckBoxSetting(object myObj
int myInt = Convert.ToInt16(myObj)
return (myInt == -1)
Then in your aspx
<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%
GetCheckBoxSetting(DataBinder.Eval(Container.DataI tem, "strainer_on_fuel_line_bool")) %>' Enabled="False"></asp:CheckBox
If returning bool doesn't set the checkbox checked property correctly then try returning a string from GetCheckBoxSetting method
protected string GetCheckBoxSetting(object myObj
int myInt = Convert.ToInt16(myObj)
if (myInt == -1
return "true"
els
return "false"
HTH
Suresh
-- Marty wrote: --
I have a numeric Oracle field which stores -1 for true and 0 fo
false. I am trying to populate a checkbox in a datagrid. In my SQ
statement, I used the Decode function so that when it populates th
dataset that I would store the string 'true' and 'false' rather than
numeric value. I did this because I thought it would make it easie
to actually set the value in the checkbox. Anyway, I bind the datase
to the datagrid. In my HTML code, the checkbox is contained in
templatecolumn
<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%
(bool) DataBinder.Eval(Container.DataItem
"strainer_on_fuel_line_bool") %>' Enabled="False"></asp:CheckBox
However, this will not work. It complains that "Specified cast is no
valid.
I have even tried it without the "(bool)" cast and it still didn'
work
The data in my database has the value stored as either a -1 or 0. I
either case, I just want to set the check box to checked or unchecked
I was even wondering if I needed to use one of the d atagrid's event
to do this
Any ideas or help is appreciated
Thanks,
Mart
It worked, thanks!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Showing posts with label populate. Show all posts
Showing posts with label populate. Show all posts
Thursday, March 29, 2012
Thursday, March 22, 2012
Set MaxLength on form Load
Hi,
Does anyone know how to populate the maxlength property of an asp:textbox on page load?
I'm getting the value from the my config table in my DB
When I try setting myControl.MaxLength=10 in the onload event
It's not written to the control and when I enter text I'm not restricted at all
I've also tried
<asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="<%=SummaryLimit%>"></asp:textbox>
' And
<asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="<%=Convert.ToInt32(SummaryLimit)%>"></asp:textbox>
Geting error - <%=SummaryLimit%> is not a valid value for Int32.
And
<%=Convert.ToInt32(SummaryLimit)%> is not a valid value for Int32.
SummaryLimit Value is declared and assigned as an Int32
Dim m_iSummaryLimit As Int32 = 250
Public Property SummaryLimit() As Int32
Get
Return Convert.ToInt32(m_iSummaryLimit)
End Get
Set(ByVal Value As Int32)
m_iSummaryLimit = Convert.ToInt32(Value)
End Set
End PropertyThe textbox control when in multiline mode actually renders as a HTML textarea therefore on a textarea there is no maxlength property so maxlength does not work. One of the ways to control this is to use javascript instead.
Basilisk,
Thanks for that, just wasted the whole morning trying to get it working.
Cheers Al
I did want to pipe in and say that when you use the following:
<%= ... %>
in an item tag, you need to surround it with single quotes - ' - and not double quotes - " -.
Lord Rat,
Thanks, feel free to pop out of your cave with useful tips like that at anytime :D
Cheers Al
Does anyone know how to populate the maxlength property of an asp:textbox on page load?
I'm getting the value from the my config table in my DB
When I try setting myControl.MaxLength=10 in the onload event
It's not written to the control and when I enter text I'm not restricted at all
I've also tried
<asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="<%=SummaryLimit%>"></asp:textbox>
' And
<asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="<%=Convert.ToInt32(SummaryLimit)%>"></asp:textbox>
Geting error - <%=SummaryLimit%> is not a valid value for Int32.
And
<%=Convert.ToInt32(SummaryLimit)%> is not a valid value for Int32.
SummaryLimit Value is declared and assigned as an Int32
Dim m_iSummaryLimit As Int32 = 250
Public Property SummaryLimit() As Int32
Get
Return Convert.ToInt32(m_iSummaryLimit)
End Get
Set(ByVal Value As Int32)
m_iSummaryLimit = Convert.ToInt32(Value)
End Set
End PropertyThe textbox control when in multiline mode actually renders as a HTML textarea therefore on a textarea there is no maxlength property so maxlength does not work. One of the ways to control this is to use javascript instead.
Basilisk,
Thanks for that, just wasted the whole morning trying to get it working.
Cheers Al
I did want to pipe in and say that when you use the following:
<%= ... %>
in an item tag, you need to surround it with single quotes - ' - and not double quotes - " -.
Lord Rat,
Thanks, feel free to pop out of your cave with useful tips like that at anytime :D
Cheers Al
Subscribe to:
Posts (Atom)