3
My application needs to release types of accesses, for example, we have 5 branches and such person needs to access content from only 3 branches.
The ADM user, can create or edit new users. When editing I need to load the accesses he already has and also what he may have.
I created a gridview and put all the affiliates there, and in the database we have the information that he already has access, per user.
Creation of the Gv:
DataTable tblACESSOfilial = new DataTable();
tblACESSOfilial.Columns.Add("ACESSOFILIAL", Type.GetType("System.String"));
tblACESSOfilial.Columns.Add("LOCALDEACESSO", Type.GetType("System.String"));
String[] tipofilial = new String[18];
tipofilial[0] = "1-1-1";
tipofilial[1] = "1-4-1";
tipofilial[2] = "1-5-7";
tipofilial[3] = "1-7-6";
tipofilial[4] = "1-123-8";
tipofilial[5] = "1-124-8";
tipofilial[6] = "1-1-2";
tipofilial[7] = "1-1-3";
tipofilial[8] = "1-1-4";
tipofilial[9] = "1-1-6";
tipofilial[10] = "1-9-126";
tipofilial[11] = "5-4-1";
tipofilial[12] = "5-1-4";
tipofilial[13] = "5-1-6";
tipofilial[14] = "5-1-7";
tipofilial[15] = "5-1-8";
tipofilial[16] = "5-1-9";
tipofilial[17] = "10-1-2";
String[] descfilial = new String[18];
descfilial[0] = "1-1-1 (Nome)";
descfilial[1] = "1-4-1 (Nome)";
descfilial[2] = "1-5-7 (Nome)";
descfilial[3] = "1-7-6 (Nome)";
descfilial[4] = "1-123-8 (Nome)";
descfilial[5] = "1-124-8 (Nome)";
descfilial[6] = "1-1-2 (Nome)";
descfilial[7] = "1-1-3 (Nome)";
descfilial[8] = "1-1-4 (Nome)";
descfilial[9] = "1-1-6 (Nome)";
descfilial[10] = "1-9-126 (Nome)";
descfilial[11] = "5-4-1 (Nome)";
descfilial[12] = "5-1-4 (Nome)";
descfilial[13] = "5-1-6 (Nome)";
descfilial[14] = "5-1-7 (Nome)";
descfilial[15] = "5-1-8 (Nome)";
descfilial[16] = "5-1-9 (Nome)";
descfilial[17] = "10-1-2 (Nome)";
for (int x = 0; x <= 17; x++)
{
DataRow rows = tblACESSOfilial.NewRow();
rows["ACESSOFILIAL"] = tipofilial[x];
rows["LOCALDEACESSO"] = descfilial[x];
tblACESSOfilial.Rows.Add(rows);
}
this.dgvACESSOfilial.DataSource = tblACESSOfilial;
this.dgvACESSOfilial.DataBind();
In the appointment I have is the following:
SELECT CODCOLIGADA, CODTIPOCURSO, CODFILIAL FROM POLIS_NCADMINFILIAL (NOLOCK)" +
"WHERE CODUSUARIO = '@CODUSUARIO'
This query can return from 0 to 17 lines.
If the content is in the query it makes a check in gridview in the following form:
List<domUsuario> list2 = dao.ListaTodosFilial(this.txtCODUSUARIO.Text);
foreach (GridViewRow row in this.dgvACESSOfilial.Rows)
{
if (list2[row.RowIndex].COLIGADAIN.Count() > 0)
{
string local = list2[row.RowIndex].COLIGADAIN + "-" + list2[row.RowIndex].CODTIPOCURSO + "-" + list2[row.RowIndex].CODFILIAL; ==>ERRO AQUI
if (local.Contains(row.Cells[1].Text))
{
CheckBox chkRow = (row.Cells[0].FindControl("chkRowfilial") as CheckBox);
chkRow.Checked = true;
}
}
}
The problem is that I have returned the error where I identified as "==>ERROR HERE":
The index was out of range. It must be non-negative and smaller than the collection size. r nName of parameter: index
Could someone help me in what I might be doing? I thank you in advance.
then, depending on the query it runs and checks on some items and after this error.. ended up not working the way it said
– PedroBelino
the error is giving why the amount of datagridview lines and items in the list are different
– Weiner Lemes
Yes, but I don’t know what way to "ignore" when it’s different.. Because I have to go through being different, so I can give
– PedroBelino
I edited the answer, see if that’s what you expect..
– Weiner Lemes
actually not yet, talking to a guy here from work.. I realized I needed to do two foreach, one for the select query and the other for the gridview and compare and it worked out.. Soon put the answer
– PedroBelino
lambda of values does a foreach on select values, but blz, I hope it works.
– Weiner Lemes
I’m still young and I don’t know much, I appreciate your help.. during this time I was trying to solve and it worked in another way
– PedroBelino
Let’s go continue this discussion in chat.
– PedroBelino