how to preselect rows in a datagrid

ndinakar

New member
Joined
May 29, 2003
Messages
2
hello

i have a datagrid with check boxes in the first column. how can i check some of these boxes when page loads ? i need to query the db and based on the value on the db ( for example - yes or no) check or uncheck the boxes.

any ideas will be greatly appreciared.
thanks in advance.
dinakar
 
You can create a DataTable and add rows manually by using Reader. According to the particular field in the query you can make checkbox true or false. This is the case if have unbound checkbox column in the datagrid.

Hope it helps.
 
jf, i didnt find my answer in that list.

i already have the datagrid with an itemtemplate column for check box column.

heres the code for the column:


<asp:TemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="Select">
<ItemTemplate>
<asp:CheckBox Runat="server" ID="chkselection" checked=<%# ChangeToCheckBox(DataBinder.Eval(Container.DataItem, "humiditycontrol"))%> Text=<%# DataBinder.Eval(Container.DataItem, "humiditycontrol") %> />
</ItemTemplate>
</asp:TemplateColumn>


and the function is :

function ChangeToCheckBox(byval len as string) as boolean
response.write("len= " & len & "<br>")
if (len="No") then
response.write("inside")
return true
else
return false
end if
end function
.
now when i run the script, the function writes the values correctly ( the response.write) but for some reason the check boxes are not getting checked.

any ideas pls?
 
Back
Top