ok, I needed to check if only 4 out of 15 textboxes were empty, but with no luck. I tried:
if txtbox1.text = "" then
lblerror1.visible=true
exitsub
else
bla bla
end if
But that left error text and didn't see the user entering the text in the textbox, so I looked and found string.isnullorwhitespace(string.value)...
well, that didn't tell me how to use it so I searched more and found this:
if string.isnullorwhitespace(textbox.text) then..
well that was it and here is the outcome. now if I could only get a for-next or do -while to only chaeck the 4 text fileds I need to check and not all textboxes.
ASPX page code:
<asp:Label ID="lblerror" runat="server" Text="Page error" Visible="false" forecolor="red"/><br />
<asp:TextBox ID="txtName" runat="server" Width="100px" /><asp:Label ID="nameblankerror" runat='server' Text="cannot be blank" ForeColor="Red" Visible="false" /><br />
<asp:TextBox ID="txtcompname" runat="server" Width="100px" /><asp:Label ID="compblankerror" runat='server' Text="cannot be blank" ForeColor="Red" Visible="false" /><br />
<asp:Button ID="btnSubmit" runat="server" Text="submit" /><br />
<asp:Label ID="lbl1" runat="server" Visible="true" Text="TextBox 1: " /><asp:label ID="lblname" runat="server" /><br />
<asp:Label ID="lbl2" runat="server" Visible="true" Text="TextBox 2: " /><asp:label ID="lblCompName" runat="server" />
and for the backend code:
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
'test to see if certain the fields are blank
Dim str1 As String = txtName.Text
Dim str2 As String = txtcompname.Text
Dim CatchMe As Integer = 0
If String.IsNullOrWhiteSpace(txtName.Text) Then
nameblankerror.Visible = True
CatchMe += 1
Else
nameblankerror.Visible = False
lblname.text = str1.Trim()
CatchMe += 0
End If
If String.IsNullOrWhiteSpace(txtcompname.Text) Then
compblankerror.Visible = True
CatchMe += 1
Else
compblankerror.Visible = False
lblCompName.Text = str2.Trim()
CatchMe += 0
End If
If CatchMe = 0 Then
'do something like process SQL Command
lblerror.Visible = False
Exit Sub
ElseIf CatchMe <> 0 Then
'return to page and process nothing
lblerror.Visible = True
Exit Sub
End If
End Sub
so that is it. a simple, easy to follow check for certain textboxes out of a bunch.
Like I stated above if I could figure out how to check only certain textboxes and not all textboxes, that and make the code shorter would be great. I put in a catchme so that if one box was filled in it wouldn't show the user that they need to fill that one also (in Error), but would catch the other empty textboxes.
to make it clear, if I have 15 textboxes, but only care that 4 of them are not empty, this is what I do for the check. I don't do this for every textbox as it is not needed
Add unique CssClass to all 4 TestBox.
Find the parent control which holds all 4 TextBox.
And then try the following code.
If you have applied validateempty as CssClass for TextBox and if Ctrl1 is the parent control which holds the textboxes then.
For Each ctrl as Control In Ctrl1.Controls
Dim txt as TextBox = TryCast(ctrl, TextBox)
If txt IsNot Nothing And txt.CssClass = "validateempty" And txt.Text.Trim() = "" Then
'Your choice of code hear.
End If
Next
Using JQuery you can find an element by its cssclass name.
First add the JQuery reference to your page You can find it hear.
Second add the following function to OnClientClick attribute of the submit button.
function validate(){
//Since you have added cssclass for the textboxes as "validateempty" then
var ret = true;
$.find(".validateempty").each(function(){
if(ret){
if($(this).val().trim() == ""){
alert("Enter the value.");
$(this).focus();
ret = false;
}
}
});
return ret;
}
$.find() will find all elements with the provided filter parameter. In this case css class. If there are more than one value is returned as there are 4 text boxes, then loop through the result and check individual found element which can be found in $(this) element. If you specify return directly inside the $.find(), then it will return from the loop not from function.
You can maintain an array of Id's you want to validate.
String[] txtboxToValidate = { "txtb1", "txtb2", "txtb4", "txtb8" };
foreach (Control c in Page.Controls)
{
if (c is TextBox)
{
int pos = Array.IndexOf(txtboxToValidate, c.ID);
TextBox txtBox = (TextBox)c;
if (pos > -1)
{
if (String.IsNullOrEmpty(txtBox.Text))
{
//Write your logic how you want to throw your error.
}
}
}
}
It's in c# but logic remains same. You can convert it to VB using online code converters etc.
Related
So I create a button in the behind code using a function in an Repeater. And then, there's a button that should take these automatically generated buttons (if I check the checkbox in button A, I take the values of row A in repeater,same goes for button B and so on...).
I can see checking the code while debugging that the checkbox are generated correctly. So I should just be able to find it, but can not. Even tho I use the findControl but have not been able to do it.
Here is the code from the front:
<asp:Panel ID="mainPanel" runat="server">
<asp:Repeater ID="repStudents" runat="server">
....
<%# GetButton(Eval("Role").ToString()) %>
....
<asp:LinkButton runat="server" OnClick="showChosen" ClientIDMode="Static"
CausesValidation="true">Save</asp:LinkButton>
And here I generate the button and then try to show the chosen value:
protected string GetButton(string status)
{
string love="";
if(status == "Rel")
{
love = "<input id='relBtn' type='checkbox' runat='server'/>";
}
else
{
love = "<input id='rfBtn' checked type='checkbox' runat='server'/>";
}
return love;
}
protected void showChosen(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)(mainPanel.FindControl("relBtn"));
if(cb.Checked)
lblError.Text = "Checkbox is checked";
else
lblError.Text = "Checkbox is not checked";
divError.Visible = true;
All I keep getting is the Null Reference Exception, even tho, there is just one relBtn in the whole page. If I look into the page generated code, I can see the relBtn, but for some reason, I can not find the Checkbox.
Ok, unless you crossed the desert, climbed mountains, exhausted every "reasonable" alternative?
You have to ask WHY you want to write code to inject a button when THAT is the WHOLE idea of quite near EVERY control from repeater, listview, Gridview and more!
In other words, the need for writing code code, and a GOOD strong case has not been made yet.
and why do we need a huge spectacular earth shaking narrative as to why the approach is being used?
Because in 99% of cases, you don't need to do this, and the data aware controls and darn near the WHOLE asp.net system is designed around you NOT having to take that road.
So, if you have some button, or whatever? Just drop it into the repeater control, and it will "repeat" over and over for you!!!
So, say this simple repeater:
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<div style="border-style:solid;color:black;width:320px;height:450px;float:left;margin-right:10px;margin-bottom:10px">
<div style="text-align:center;padding:2px 10px 2px 10px" class="cards" >
<asp:Button ID="cmdMyView" runat="server" Text="View"
CssClass="btn-info" style="float:right"
CommandArgument = '<%# Eval("ID") %>'
OnClick="cmdMyView_Click" />
<br />
<h3 id="hFighter" runat="server"><%# Eval("Fighter") %></h3>
<asp:Image ID="Image2" runat="server"
ImageUrl = '<%# Eval("ImagePath") %>' Width="170" />
<h4>Engine</h4>
<asp:Label ID="EngineLabel2" runat="server" Text='<%# Eval("Engine") %>' />
<h4>Description</h4>
<asp:Label ID="DescLabel" runat="server" Text='<%# Eval("Description") %>' />
<br />
</div>
</div>
</ItemTemplate>
</asp:Repeater>
Note the button and the plain jane click event for that button.
So, to fill the repeater, we have this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadData()
End If
End Sub
Sub LoadData()
Using conn As New SqlConnection(My.Settings.TEST4)
Dim strSQL As String =
"SELECT * FROM Fighters"
Using cmdSQL As New SqlCommand(strSQL, conn)
conn.Open()
Dim rstData As New DataTable
rstData.Load(cmdSQL.ExecuteReader)
Repeater1.DataSource = rstData
Repeater1.DataBind()
End Using
End Using
End Sub
And now we see/get this:
And now that button click from above (the view button).
Protected Sub cmdMyView_Click(sender As Object, e As EventArgs)
Dim btn As Button = sender
Dim rRow As RepeaterItem = btn.NamingContainer
Debug.Print("Row index = " & rRow.ItemIndex)
Debug.Print("DATA ID pk = " & btn.CommandArgument)
Dim hFighter As HtmlGenericControl = rRow.FindControl("hFighter")
Debug.Print("Figher name = " & hFighter.InnerText)
End Sub
output:
Row index = 3
DATA ID pk = 4
Figher name = Lockheed Martin F-35 Lightning II
So, note how the the simple button click picks up the current row of data.
From that, we can use find control, or get the "row index" of the click, or in our case, we also included the database PK id in the button command arugment.
So, VERY hard to make a case to do all those "hand stands" to write code to "inject" a button when darn near ALL of the data aware controls will repeat the data AND the controls for you over and over with great ease, and in fact ZERO code to have such buttons or controls repeat for you.
there are RARE cases to write code to inject, but they should be the last resort, since in 99% of cases, no such code is required, and worse yet, when you post-back, such injected controls will NOT persist, and you have to re-inject on every post back for such pages to work.
Edit: So, this could be used
markup:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<i id="iHotel" runat="server"><%# Eval("HotelName") %></i>
<br />
<asp:CheckBox ID="chkREL" runat="server"
Checked='<%# Eval("Status").ToString() == "Rel" ? true : false %>' />
<br />
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />
<hr />
</ItemTemplate>
</asp:Repeater>
Say code to load:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
void LoadData()
{
Repeater1.DataSource = General.MyRst("SELECT * FROM tblHotelsA");
Repeater1.DataBind();
}
result is this:
Button click:
protected void Button1_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
RepeaterItem iRow = (RepeaterItem)btn.NamingContainer;
Debug.Print($"Row click index = {iRow.ItemIndex}");
CheckBox chkRel = (CheckBox)iRow.FindControl("chkREL");
Debug.Print($"Check box checked = {chkRel.Checked}");
HtmlGenericControl iHotel = (HtmlGenericControl)iRow.FindControl("iHotel");
Debug.Print($"Hotel name from 'p' item = {iHotel.InnerText}");
}
output:
Row click index = 1
Check box checked = True
Hotel name from 'p' item = Ramada Lodge
I have a gridview displaying data within a template field which requires more information about the record to be displayed by clicking on a linkbutton. Right now, I have the "details" linkbutton display the information by calling the edit command on the gridview so that it switches to the EditItemTemplate. Within the EditItemTemplate I have a linkbutton for cancel and then an edit button that, when clicked, displays the update button with the update command, but I need it to iterate through that row and set all the textboxes within the EditItemTemplate to ReadOnly=false so as to allow them to be edited before the update command is selected. Here is a summary of the code:
<ItemTemplate>
*basic information displayed*
<asp:LinkButton runat="server" CommandName="Edit" Text="Details"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
*A bunch of readonly textboxes that display the extra information*
<asp:LinkButton runat="server" CommandName="Update" Text="Update" Visible="false"></asp:LinkButton>
<asp:LinkButton runat="server" Text="Edit" OnClick="editButton_Click"></asp:LinkButton>
</EditItemTemplate>
And the code for the event which makes the buttons appear the way I want, but I'm not sure how to iterate through the EditItemTemplate, or even if this is what I should do:
Protected Sub editButton_Click(sender As Object, e As EventArgs)
sender.FindControl("updateButton").Visible = True
sender.FindControl("editbutton").Visible = False
For Each t In ?EditItemTemplate?
Dim textbox = TryCast(t, System.Web.UI.WebControls.TextBox)
If textbox IsNot Nothing Then
textbox.ReadOnly = False
End If
Next
End Sub
So my question is either how to get this to work, or how I should set up the GridViewCommands otherwise
You should use a PlaceHolder in your EditItemTemplate. Place all of your Controls/LinkButtons inside this placeholder.
<EditItemTemplate>
<asp:PlaceHolder ID="TestPlaceHolder" runat="server">
// Sample Link Buttons
<asp:LinkButton runat="server" CommandName="Update" Text="Update"
Visible="false"></asp:LinkButton>
<asp:LinkButton runat="server" Text="Edit" OnClick="editButton_Click"></asp:LinkButton>
// Sample Text Box
<asp:TextBox runat="server" ID="FirstName" ...>...</TextBox>
</asp:PlaceHolder>
</EditItemTemplate>
Handle the RowEditing event of GridView. Inside the edit event handler, first find the Placeholder, then use the PlaceHolder's Controls property to iterate over the Controls...
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
// Get the Placeholder for the row being edited.
PlaceHolder testPlacehldr =
GridView.Rows[e.NewEditIndex].FindControl("TestPlaceholder") as PlaceHolder;
// Iterate over the controls
if(testPlacehldr.Controls.Count > 0)
{
foreach (Control ctrl in testPlacehldr.Controls)
{
if (ctrl is LinkButton)
{
LinkButton lnkBtn = ctrl as LinkButton
if(lnkBtn.Text== "Update")
{
lnkBtn.Visible = false;
}
// More IF conditions follow....
}
if (ctrl is TextBox)
{
TextBox txtBox = ctrl as TextBox;
if(txtBox.ID == "FirstName")// use any property of TexBox you prefer
{
txtBox.ReadOnly= true;
}
// More IF conditions follow....
}
}
}
//At the End, set the EditIndex and Bind the data
GridView1.EditIndex = e.NewEditIndex;
BindGridViewData();
}
I hope you can workout the logic yourself now for hiding/showing the controls.
So I figured out how to do it (needed it in vb) by using the placeholder within the EditItemTemplate, here's the code behind it:
Protected Sub editButton_Click(sender As Object, e As EventArgs)
sender.FindControl("editbutton").Visible = False
sender.FindControl("updateButton").Visible = True
Dim testPlacehldr As PlaceHolder = sender.FindControl("TestPlaceholder")
If testPlacehldr.Controls.Count > 0 Then
Dim btn As LinkButton = sender.FindControl("editButton")
If btn.Visible = False Then
For Each ctrl As Control In testPlacehldr.Controls
If ctrl.GetType Is GetType(TextBox) Then
Dim box As TextBox = TryCast(ctrl, TextBox)
box.ReadOnly = False
End If
Next
End If
End If
End Sub
This works fine for what I need it to do. Credit to the user R.C. for the idea about placeholders
I currently have a GridView with two buttons that I have added using the following code;
<asp:GridView ID="gvResults" AutoGenerateColumns="False" runat="server" Font-Size="small"
DataKeyNames="BeachHutID" OnRowDataBound="gvResults_RowDataBound" CssClass="BBCSearch">
<Columns>
<asp:BoundField DataField="BeachHutID" SortExpression="BeachHutID" Visible="false">
</asp:BoundField>
<asp:ImageField DataImageUrlField="HutImage" ItemStyle-Width="1%" ReadOnly="true" />
<asp:BoundField HeaderText="Facilities" DataField="Facilities" Visible="false"></asp:BoundField>
<asp:BoundField HeaderText="Info" DataField="Info" Visible="false"></asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:PlaceHolder ID="lblHolder" runat="server"></asp:PlaceHolder>
<br />
<asp:PlaceHolder ID="imgHolder" runat="server"></asp:PlaceHolder>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnHire" CommandArgument='<%# Eval("BeachHutID") %>' runat="server"
Text="Hire Beach Hut" OnClick="Hire_Click" />
<asp:Button ID="ButtonLogin" CommandArgument='<%# Eval("BeachHutID") %>' runat="server"
Text="Login to Hire Beach Hut" OnClick="Login_Redirect" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
What I want to happen is if the user is logged in, the btnHire button should be enabled and showing and if they're not logged in, ButtonLoggedIn is showing and btnHire is hidden. This is the code I have at the moment;
Public Sub PopulateGrid()
Dim AvailableHuts As New DataTable
AvailableHuts = GetData()
gvResults.DataSource = AvailableHuts
gvResults.DataBind()
gvResults.Enabled = True
'If statement controlling the enabling and disabling of the Beach Hut booking button
If Session("LoginID") = "" Then
For Each rowItem As GridViewRow In gvResults.Rows
rowItem.Cells(5).Enabled = True
Next
End If
lblCaption.Text = "Your search returned " + CStr(AvailableHuts.Rows.Count) + " results"
End Sub
At the moment both buttons are enabled at all times and I'm not sure what I need to add/changed to get the desired result.
From the answer posted by #Andrei, I have added the following to to this Sub;
Protected Sub gvResults_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvResults.RowDataBound
Dim URL(), Text() As String
Dim img As Image
Dim lbl As Label
Dim FacilitiesImg As PlaceHolder = e.Row.FindControl("imgHolder")
Dim Infolbl As PlaceHolder = e.Row.FindControl("lblHolder")
'Added Code from answer
Dim hireBtn As Button = CType(e.Row.FindControl("btnHire"), Button)
hireBtn.Visible = Not String.IsNullOrEmpty(Session("LoginID"))
'Added Code from answer
Dim LoginBtn As Button = CType(e.Row.FindControl("ButtonLogin"), Button)
LoginBtn.Visible = String.IsNullOrEmpty(Session("LoginID"))
If e.Row.RowType = DataControlRowType.DataRow Then
URL = e.Row.DataItem(3).Split(",")
Text = e.Row.DataItem(2).Split(",")
'Add the Facilities Images to the grid Row
For Each item In URL
If item.ToString <> "" Then
img = New Image
img.ImageUrl = item.ToString
FacilitiesImg.Controls.Add(img)
End If
Next
'Add the information to the grid row
'convert # into a carriage return and * into £
For Each item In Text
If item.ToString <> "" Then
lbl = New Label
lbl.Text = Replace(Replace(item.ToString, "#", "<br />"), "*", "£")
Infolbl.Controls.Add(lbl)
End If
Next
End If
End Sub
However I'm receiving the following error when trying to run the program;
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class
Any assistance would be much appreciated.
Thanks
Not sure how is your authentication implemented, but let's assume you use HttpContext.Current.Request.IsAuthenticated. Then you can just manipulate Visible property of the buttons in code behind:
btnHire.Visible = HttpContext.Current.Request.IsAuthenticated
ButtonLoggedIn.Visible = Not HttpContext.Current.Request.IsAuthenticated
Update.
Sorry, somehow missed from the post the fact that you seems to be using Session("LoginID") to decide if the use is logged in. The you can do this:
btnHire.Visible = Not String.IsNullOrEmpty(Session("LoginID"))
ButtonLoggedIn.Visible = String.IsNullOrEmpty(Session("LoginID"))
Update 2.
As it turns out, buttons are a part of GridView row. As they are inside the template, you cannot really reach them in the code behind. So you can take two options.
First, you can subscribe to RowDataBound event (which you already did), and inside it do FindControl in the current row to find the necessary button:
Sub gvResults_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
...
Button hireBtn = CType(e.Row.FindControl("btnHire"), Button);
hireBtn.Visible = Not String.IsNullOrEmpty(Session("LoginID"))
and likewise for the second button.
Second, you can try doing it in the markup:
<asp:Button ID="btnHire" CommandArgument='<%# Eval("BeachHutID") %>'
runat="server" Text="Hire Beach Hut" OnClick="Hire_Click"
Visible=<%# String.IsNullOrEmpty(Session("LoginID")) %> />
try
<asp:Button ID="btnHire" CommandArgument='<%# Eval("BeachHutID") %>' runat="server" Visible='<%# islogin()?true:false %>' Text="Hire Beach Hut" OnClick="Hire_Click" />
<asp:Button ID="ButtonLoggedIn" CommandArgument='<%# Eval("BeachHutID") %>' runat="server" Visible='<%# islogin()?false:true %>' Text="Login to Hire Beach Hut" OnClick="Login_Redirect" />
paste this code to aspx.cs page:
Public Shared Function isLogin() As Boolean
Dim stat As Boolean = False
Try
If Session("LoginID") IsNot Nothing AndAlso Session("LoginID") <> "" Then
stat = True
End If
Catch e1 As Exception
stat = False
End Try
Return stat
End Function
Edit2:
Visible='<%# islogin()?false:true %> this means if isLogin() return true then Visible property set to false else it's visible property set to true.
I have the following code which works fine if checking whether the selected value of a dropdownlist is greater than 0.
However, I need to check against the selected index of the dropdownlist rather than the value.
Sub selectValidation(source As Object, args As ServerValidateEventArgs)
Try
args.IsValid = args.Value > 0
Catch ex As Exception
args.IsValid = False
End Try
End Sub
Changing .Value to .SelectedIndex creates the following error:
BC30456: 'SelectedIndex' is not a member of 'System.Web.UI.WebControls.ServerValidateEventArgs'.
EDIT:
Here's the validator code...
<asp:DropDownList runat="server" ID="Adults" AutoPostBack="true" />
<asp:CustomValidator id="Req_Adults"
ControlToValidate="Adults"
ClientValidationFunction="selectValidation"
OnServerValidate="selectValidation"
runat="server"
CssClass="errorAsterisk"
Text="*"
ErrorMessage="Select number of adults" />
<asp:DropDownList runat="server" ID="Children" AutoPostBack="true" />
<asp:CustomValidator id="Req_Children"
ControlToValidate="Children"
ClientValidationFunction="selectValidation"
OnServerValidate="selectValidation"
runat="server"
CssClass="errorAsterisk"
Text="*"
ErrorMessage="Select number of children" />
Clientside validation (working fine):
function selectValidation(source, arguments)
{
var selectedValue = $(source).siblings("select").prop("selectedIndex");
if (selectedValue > 0 ){
arguments.IsValid = true;
} else {
arguments.IsValid = false;
}
}
If the DropDownList is directly accessible from the handler, this works:
Sub selectValidation(source As Object, args As ServerValidateEventArgs)
args.IsValid = Me.DropDownList1.SelectedIndex <> -1
End Sub
Otherwise you have to show us where it is. You canot get the reference from source or args.
A CustomValidator is the only validator which does not need to have a ControlToValidate. It can validate multiple controls, hence it wouldn't make sense to pass a control.
Update
I don't like this approach. However, if you really want to use the same handler you can assign a ValidationGroup to all relevant DropDownLists and use a query like this to find them:
Dim ddlNumZero = From ddl In Me.Controls.OfType(Of DropDownList)()
Where ddl.ValidationGroup = "NumberValidation" _
AndAlso ddl.SelectedIndex <= 0
args.IsValid = Not ddlNumZero.Any()
I've got an aspx using master pages and .net 4. I've using the same code on 4 different forms. I've copied and pasted it from the other forms that are working. Here is the code.
The listview is named lvMisc_Attachment, here is the Checkbox code
<asp:CheckBox ID="chkChecked" runat="server" Checked='<%#eval("Checked") %>' />
and here is the code behind that is happening when someone clicks a linkbutton, the linkbutton calls teh MiscAttachment_ItemsChecked function.
Private Function MiscAttachment_ItemsChecked() As String
Dim mString As String = String.Empty
For Each lv In Me.lvMisc_Attachment.Items
If CType(lv.FindControl("chkChecked"), CheckBox).Checked = True Then
If mString.Length = 0 Then
mString = CType(lv.FindControl("hfMisc_AttachmentID"), HiddenField).Value
Else
mString = mString & "," & CType(lv.FindControl("hfMisc_AttachmentID"), HiddenField).Value
End If
End If
Next
Return mString
End Function
The checkbox does not show up as being checked when it is. It is getting checked after the page renders.
Add AutoPostback="true" to your checkbox in order to post contol whan he changes
<asp:CheckBox ID="chkChecked" runat="server" Checked='<%#eval("Checked") %>' AutoPostback="true"/>
I found the problem. I forgot to do a if page.ispost=true on the page_Load.. the listview was getting repopulated so the checkbox wasn't checked due to the reload.