1
I have a string in the format ["0,1,0,1,0,1,0,0"]. Where 1 is checked and 0 is unchecked. I also have a grid where I still have a checkbox at the first Oluma. I need to mark the checkboxes according to my string. I tried at first using Javascript, but could not.
C# :
protected void Page_Load(object sender, EventArgs e)
{
Session["Checados"] = Checados;
.
.
.
}
JS and Aspx:
<div class="CentralizarGrid">
<asp:GridView ID="_gvPontoParada" CssClass="table table-striped grid-table" runat="server" AutoGenerateColumns="False" EnableModelValidation="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnDataBound="_gvPontoParada_DataBound" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Código" DataField="Codigo" />
<asp:BoundField HeaderText="Descrição" DataField="Descricao" />
<asp:BoundField HeaderText="Endereço" DataField="Endereco" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</div>
.
.
.
<script type="text/javascript">
var Checados='<%= (Session["Checados"].ToString())%>';
var check= Checados.split(",");
function verifica(chk) {
for(var i = 0; i < check.length; i++)
{
if (check[i] == "0")
{
document.getElementById(chk).checked = false;
} else if (check[i] == "1")
{
document.getElementById(chk).checked = true;
}
}
}
Thanks for the help!!