1

I want to bind bool value to repeater .

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<br />
<img ID="ImageZoom" runat="server" src='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %> '  style="display: inline; height:auto; left: 0pt; top: 0pt; width:auto;" />
    <asp:CheckBox ID="CheckBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ImageId") %> ' Checked='<%# DataBinder.Eval(Container.DataItem, "Boolv") %>' /> 

</ItemTemplate>
</asp:Repeater>

Here on page load checked should have only true or false but its returning checked . How can i get true or false ?

Valamas
  • 24,169
  • 25
  • 107
  • 177
user1619151
  • 59
  • 1
  • 2
  • 6

5 Answers5

2

Instead to fiddling around on the aspx markup, i would do that in ItemDataBound:

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    RepeaterItem ri = e.Item;
    DataRowView dr = (DataRowView)ri.DataItem;
    CheckBox CheckBox1 = (CheckBox)ri.FindControl("CheckBox1");
    CheckBox1.Checked = (bool)dr["Boolv"];
}
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • @user1619151: Is `Boolv` a boolean at all? You say that _"its returning checked"_ instead of `true/false`. Maybe you've stored a string _"checked"_. Then try this: `CheckBox1.Checked = dr["Boolv"].Equals("checked");`. – Tim Schmelter Aug 27 '12 at 08:44
  • ya . i did , its correctly coming there when i debug , but in ascx page I am getting like above . I saw this by using inspect element – user1619151 Aug 27 '12 at 08:45
0

several days ago, I also had a problem with repeater and a checkbox in it. I wanted to bind the value of the checkbox to bool variable.

Here is my post. I've solved my problem using the accepted answer in the post. answer link

Cheers!

Community
  • 1
  • 1
Anton Belev
  • 11,963
  • 22
  • 70
  • 111
0

I you want to dot this in clientSide use eval if statement

<asp:CheckBox ID="CheckBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ImageId") %> ' Checked='<%# ((int)Eval("Boolv")) == 1 ? Checked : false %>' /> 
AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197
0

Use OnItemDataBound event on Repeater Control

here my answer to similar question

hope it's help:)

Community
  • 1
  • 1
Harry89pl
  • 2,415
  • 12
  • 42
  • 63
0

In one of my implementations, I was getting 1 and 0 from database for the boolean value so my implementation for it was as:

<asp:CheckBox ID="chkAssign" runat="server" Checked=<%# TranslateAction(((System.Data.DataRowView)Container.DataItem)["ISACTIVE"].ToString())%> />

and in the code behind I had a method named TranslateAction as:

protected Boolean TranslateAction(String status)
{
    if (status == "1")
        return true;
     else
        return false;
}

I hope it will help you in it.

Imran Balouch
  • 2,170
  • 1
  • 18
  • 37