Ask a Question related to ASP.NET General, Design and Development.
-
John Saunders #1
Re: Problem with DataBinding and CheckBoxList
What does your Page_Load look like?
--
John Saunders
Internet Engineer
[email]john.saunders@surfcontrol.com[/email]
"Eric Johannsen" <funmx@hotmail.com> wrote in message
news:uPlZa.2$%p6.739429@newssvr14.news.prodigy.com ...go> Hi all,
>
> I have a business object with some boolean fields. They need to be
> represented as a CheckBoxList on an aspx page. I do the data binding just
> like in the examples and everything displays just fine. However, when I> to read out the new values from chklAvoid (my CheckBoxList), accessing
> chklAvoid[0] produces an error.
>
> When I do a Quick Watch on that variable, I note that the embedded
> ListControl's items.listItems property has a count of 0. Normally this
> would contain my bound items as far as I understand.
>
> HELP!
>
> Thanks,
>
> Eric
>
> Code follows:
>
> test.aspx:
> =========
> <asp:CheckBoxList id="chklAvoid" runat="server" DataSource="<%#
> this.createDataSourceAvoid() %>" DataValueField="BoolValue"
> DataTextField="Name">
> </asp:CheckBoxList>
>
> test.aspx.cs:
> ============
> private DataRow getCheckboxRow(DataTable dt, bool isChecked, string name)
> {
> DataRow dr = dt.NewRow();
> dr[0] = isChecked;
> dr[1] = name;
> return dr;
> }
>
> protected ICollection createDataSourceAvoid()
> {
> DataTable dt = new DataTable();
> dt.Columns.Add(new DataColumn("BoolValue", typeof(bool)));
> dt.Columns.Add(new DataColumn("Name", typeof(string)));
> dt.Rows.Add(getCheckboxRow(dt, myObject.Boolean1, "Text for boolean
> 1"));
> dt.Rows.Add(getCheckboxRow(dt, myObject.Boolean2, "Text for boolean
> 2"));
> DataView dv = new DataView(dt);
> return dv;
> }
>
> private void btnUpdate_Click(object sender, System.EventArgs e)
> {
> mCustomer.AvoidBreads = chklAvoid.Items[0].Selected;
> mCustomer.AvoidDairy = chklAvoid.Items[1].Selected;
> }
>
>
John Saunders Guest
-
compositedataboundcontrol with template databinding problem
Hi everyone, I am new to this ASP.NET 2.0 feature. I am having a hard time getting the databinding syntax evaluated in my template for a control... -
Controling the 'selected' property on CheckBoxList while DataBinding()
Hi Group! When binding the CheckBoxList control, you can only control the 'text' and 'value' properties of each CheckBox created. Suppose I... -
Problem handling DataGrid TemplateColumn Databinding Event
I have spent several hours trying to research and/or fix the following problem: Environment: VB.Net 2003 Scenario: I have a dynamically... -
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'"
I am creating a custom column that inherits from DataColumnGrid. When I attempt Databind to a property of the custom column, I get the the error: ... -
Control derived from datagrid, problem with adding other control and databinding (VB)
I all, my employer required me to add a bunch of control to a datagrid (such as a drop down list on top corner to select page size and prev, bunch... -
Eric Johannsen #2
Re: Problem with DataBinding and CheckBoxList
Don't have the code in front of me right now, but it's very much like
this:
Page_Load(... standard parms ...)
{
if (!IsPostBack) DataBind();
}
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Eric Johannsen Guest
-
Rick Strahl [MVP] #3
Re: Problem with DataBinding and CheckBoxList
Is ViewState enabled on the form and on the control? Without you'd have to
rebind each time and if you do you loose the state (selection) of the
control.
+++ Rick ---
--
Rick Strahl
West Wind Technologies
[url]http://www.west-wind.com/[/url]
[url]http://www.west-wind.com/wwHelp[/url]
----------------------------------
Making waves on the Web
"Eric Johannsen" <funmx@hotmail.com> wrote in message
news:uPlZa.2$%p6.739429@newssvr14.news.prodigy.com ...go> Hi all,
>
> I have a business object with some boolean fields. They need to be
> represented as a CheckBoxList on an aspx page. I do the data binding just
> like in the examples and everything displays just fine. However, when I> to read out the new values from chklAvoid (my CheckBoxList), accessing
> chklAvoid[0] produces an error.
>
> When I do a Quick Watch on that variable, I note that the embedded
> ListControl's items.listItems property has a count of 0. Normally this
> would contain my bound items as far as I understand.
>
> HELP!
>
> Thanks,
>
> Eric
>
> Code follows:
>
> test.aspx:
> =========
> <asp:CheckBoxList id="chklAvoid" runat="server" DataSource="<%#
> this.createDataSourceAvoid() %>" DataValueField="BoolValue"
> DataTextField="Name">
> </asp:CheckBoxList>
>
> test.aspx.cs:
> ============
> private DataRow getCheckboxRow(DataTable dt, bool isChecked, string name)
> {
> DataRow dr = dt.NewRow();
> dr[0] = isChecked;
> dr[1] = name;
> return dr;
> }
>
> protected ICollection createDataSourceAvoid()
> {
> DataTable dt = new DataTable();
> dt.Columns.Add(new DataColumn("BoolValue", typeof(bool)));
> dt.Columns.Add(new DataColumn("Name", typeof(string)));
> dt.Rows.Add(getCheckboxRow(dt, myObject.Boolean1, "Text for boolean
> 1"));
> dt.Rows.Add(getCheckboxRow(dt, myObject.Boolean2, "Text for boolean
> 2"));
> DataView dv = new DataView(dt);
> return dv;
> }
>
> private void btnUpdate_Click(object sender, System.EventArgs e)
> {
> mCustomer.AvoidBreads = chklAvoid.Items[0].Selected;
> mCustomer.AvoidDairy = chklAvoid.Items[1].Selected;
> }
>
>
Rick Strahl [MVP] Guest



Reply With Quote

