Hi! I want bind GridView from database using ArrayList. But my code not worked. Who is you can help me? I shared code below:
public System.Collections.ArrayList GetTime(int user, int kod)
{
SqlConnection con = new SqlConnection(UserData);
SqlCommand cmd = con.CreateCommand();
System.Collections.ArrayList result = new System.Collections.ArrayList();
string sql = "select kod,dshbe,sshbe,chshbe,pshbe,jma,shbe,koduser where koduser ="+user+"and kod =" + vr;
cmd.CommandText = sql;
con.Open();
try
{
System.Data.SqlClient.SqlDataReader r = cmd.ExecuteReader();
if (r != null)
{
while (r.Read())
{
GetDay d = new GetDay();
d.kod = r.GetInt32(0);
d.dsh = r.GetString(1);
d.ssh = r.GetString(2);
d.chsh = r.GetString(3);
d.psh = r.GetString(4);
d.jma = r.GetString(5);
d.shb = r.GetString(6);
d.user = r.GetInt32(7);
result.Add(d);
}
}
}
catch { }
con.Close();
return result;
}
[Serializable]
public class GetDay
{
public int kod;
public string dsh;
public string ssh;
public string chsh;
public string psh;
public string jma;
public string shb;
public int user;
}
<asp:GridView ID="Grid" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333"
GridLines="None" Width="550px" onrowdatabound="Grid_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="DSHBE" HeaderText="Monday" ReadOnly="True" >
<ControlStyle Width="20px" />
<FooterStyle Width="20px" HorizontalAlign="Center" />
<HeaderStyle Width="20px" />
<ItemStyle Width="20px" />
</asp:BoundField>
<asp:BoundField DataField="SSHBE" HeaderText="Tuesday" ReadOnly="True" >
<ControlStyle Width="20px" />
<FooterStyle Width="20px" />
<HeaderStyle Width="20px" />
<ItemStyle Width="20px" />
</asp:BoundField>
<asp:BoundField DataField="CHSHBE" HeaderText="Wednesday" ReadOnly="True" >
<ControlStyle Width="20px" />
<FooterStyle Width="20px" />
<HeaderStyle Width="20px" />
<ItemStyle Width="20px" />
</asp:BoundField>
<asp:BoundField DataField="PSHBE" HeaderText="Thursday" ReadOnly="True" >
<ControlStyle Width="20px" />
<FooterStyle Width="20px" />
<HeaderStyle Width="20px" />
<ItemStyle Width="20px" />
</asp:BoundField>
<asp:BoundField DataField="JMA" HeaderText="Friday" ReadOnly="True" >
<ControlStyle Width="20px" />
<FooterStyle Width="20px" />
<HeaderStyle Width="20px" />
<ItemStyle Width="20px" />
</asp:BoundField>
<asp:BoundField DataField="SHBE" HeaderText="Saturday" ReadOnly="True" >
<ControlStyle Width="20px" />
<FooterStyle Width="20px" />
<HeaderStyle Width="20px" />
<ItemStyle Width="20px" />
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>